Selftype: an idea from Scala for D2.0

Reiner Pope some at address.com
Sun May 27 00:24:40 PDT 2007


eao197 wrote:
> That is not a desired situation :)
> I don't want multiple classes inherited from Subject!(Display, Sensor). 
> I want to have multiple distinct classes inherited from Subject (for 
> example: SubjectObserver!(Notificator, Account) for banking accounting 
> system, SubjectObserver!(Display, Sensor) for data acquisition system, 
> SubjectObserver!(Mailbox, Topic) for message delivery system and so 
> on)). Class Subject in template SubjectObjserver may be inherited from 
> another useful class (Serializabe, Loggable, Dumpable or something 
> else). This means that in the following case:
> 
> class Account : SubjectObserver!(Notificator, Account).Subject { ... }
> class Topic : SubjectObserver!(Mailbox, Topic).Subject { ... }
> 
> classes Account and Topic will be automatically derived from 
> Serializable (Loggable, Dumpable, ...) too.
> 
> In case of:
> 
> class Account {
>   mixin Subject!(Notificator, Account);
>   ...
> }
> class Topic {
>   mixin Subject!(Mailbox, Topic);
>   ...
> }
> 
> it is neccessary to derive Account and Topic from Serializable 
> (Loggable, Dumpable, ...) manually.
I see, you're right. :)

As a side not, there's one pattern which could be interesting in this 
kind of situation:

template Subject(O, S)
{
     ... // Implementation details

     alias Tuple!(Loggable, Dumpable, ...) ImplementedInterfaces;
}

...

class Account : Subject!(Notifier, Account).ImplementedInterfaces {
     mixin Subject!(Notifier, Account);
}

   -- Reiner



More information about the Digitalmars-d mailing list