property magic for inerfaces (please!)
Hasan Aljudy
hasan.aljudy at gmail.com
Sat Nov 18 21:21:29 PST 2006
Reiner Pope wrote:
> == Quote from Daniel Keep (daniel.keep.lists at gmail.com)'s article
>> There are two ways of doing this, depending on the situation.
>> The first is to have an abstract base class, which allows you to add
>> partial implementation.
>> The other is to provide a mixin for the "default" implementation of
>> certain methods.
That's a possible solution, but it's still adds the inconvenience of
having to know which mixins go with the interface whenever you want to
implement it.
> The problem with both of these solutions is that they are conceptually wrong,
> since they involve adding hasChildren to the vtbl, meaning it could have any
> implementation. What Hasan was asking for was the ability for interfaces to
> declare final methods in interfaces, which would mean they can't be overridden.
>
> To achieve this the "proper" way you either need to support final methods in
> interfaces or extension methods. Of course, the latter is already partly
> implemented, and is a much more powerful feature, so I think it should be added to
> D in any case.
Maybe final methods would work better ..
Imagine a class that implements IPerson
class Kid : IPerson
{
...
}
Without final methods, "Kid" won't really have access to the magic
properties of IPerson.
Kid k = ...
...
if( k.hasChildren() ) //ops, no such property for class Kid
{
...
}
More information about the Digitalmars-d
mailing list