[D.typesystem] Suggestion for improving OO inheritance models
retard
re at tard.com.invalid
Wed Sep 1 14:56:11 PDT 2010
Wed, 01 Sep 2010 23:30:08 +0200, Jacob Carlborg wrote:
> On 2010-09-01 22:44, Philippe Sigaud wrote:
>> On Wed, Sep 1, 2010 at 18:13, retard <re at tard.com.invalid> wrote:
>>
>>
>> Have you taken a loot at Scala & traits already? It would be a
>> great starting point.
>>
>>
>> Scala's traits are great! Implicits in Scala are quite interesting too.
>> Also, Haskell typeclasses
>>
>> I wonder if D can have part of Scala traits functionality with mixins?
>
> You can't use D template mixins to add methods that will overload
> existing methods.
I'm afraid D's template mixins are like a poor man's copy/paste macro
system. Scala's approach takes subtyping into account. D 2 took a step
towards traits actually since it allows some implementations & contracts
in interfaces. However, Scala is more flexible. Scala's design had the
focus on nice OOP properties the whole time, but D will probably only get
features if implementing them efficiently is a low hanging fruit.
One interesting feature in Scala are the types of objects in this case:
class A {}
trait T {}
class B extends A with T {}
val foo = (new B) : (A with T)
--
I suppose D doesn't allow this:
class A {}
interface T {}
class B : A, T {}
(A & T) foo = new B
In Scala the inheritance graph looks like:
Any
|
AnyRef
|
Object
|
A ____ T
| /
A with T
|
B
In D it's just:
Object
|
A ____T
| /
B
More information about the Digitalmars-d
mailing list