Selftype: an idea from Scala for D2.0

eao197 eao197 at intervale.ru
Sat May 26 22:12:32 PDT 2007


On Sun, 27 May 2007 05:23:55 +0400, Reiner Pope <some at address.com> wrote:

>>  class Sensor
>>   {
>>     mixin Subject!(Display, Sensor);
>>      private char[] label_;
>>     private double value_;
>>      this( char[] label, double value )
>>       {
>>         label_ = label.dup;
>>         value_ = value;
>>       }
>>      char[] label() { return label_; }
>>     double value() { return value_; }
>>     void value( double v ) { value_ = v; publish; }
>>   }
>>  class Display : Observer!(Sensor)
>>   {
>>     void notify( Sensor subj )
>>       {
>>         Stdout( subj.label )( " has value " )( subj.value ).newline;
>>       }
>>   }
>
> 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.

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list