Selftype: an idea from Scala for D2.0

eao197 eao197 at intervale.ru
Sat May 26 23:53:00 PDT 2007


On Sun, 27 May 2007 09:26:56 +0400, Reiner Pope <some at address.com> wrote:

>>> Using the syntax Subject is S automatically requires that any  
>>> implementors of Subject!(Display, Sensor) inherit from Sensor. So why  
>>> not simply make Sensor the inheritance root, as the mixin does? I  
>>> don't see that any information is lost this way.
>>  In that example Sensor doesn't inherit from Subject. The base type for  
>> Sensor is Object.
>> But may be situations in such a class must be inherited from some  
>> domain-specific base class.
>
> I simply can't see the situation you describe. Suppose we had a  
> situation where you needed multiple classes to inherit from  
> Subject!(Display, Sensor).

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.

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list