Selftype: an idea from Scala for D2.0

eao197 eao197 at intervale.ru
Fri May 25 22:13:54 PDT 2007


On Sat, 26 May 2007 00:30:11 +0400, Jari-Matti Mäkelä  
<jmjmak at utu.fi.invalid> wrote:

>> abstract class SubjectObserver {
>>    type S <: Subject;
>>    type O <: Observer;
>>    abstract class Subject requires S { /* (1) */
>>      private var observers: List[O]  List();
>>      def subscribe(obs: O)  /* (2) */
>>         observers  obs :: observers;
>>      def publish         for (val obs <observers)
>>            obs.notify(this);  /* (3) */
>>    }
>>
>>    abstract class Observer {
>>      def notify(sub: S): unit; /* (4) */
>>    }
>> }
>
> I can see how this removes the need for "unsafe" casts. However, it might
> cause some extra trouble to the planned reflection support :) From what
> I've read and heard, Scala does not yet support reflection.

I'm not a Scala programmer so I don't know what the current situation with  
refelection is.
But some support of refelection exits:  
http://www.scala-lang.org/docu/files/api/scala/reflect$content.html

> Can you show how this would work if there were multiple subclasses
> of 'Subject' and 'Observer'? (for example multiple sensor types in the
> SensorReader example) Does it require language support for multiple
> dispatch then?

Do you what to see Scala example?

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list