interfaces :-(

John Demme me at teqdruid.com
Fri Mar 10 00:23:03 PST 2006


Walter Bright wrote:
> "John Demme" <me at teqdruid.com> wrote in message
> news:dur87c$2m44$1 at digitaldaemon.com...
>> Fine.  I'll give you a harder example:
>>
>> interface Map (K,V)
>> {
>>        V get (K k);
>>        Map copy();
>> }
>>
>> class HashMap (K,V): Map!(K,V)
>> {
>>        V get(K k) {}
>>        void rehash() {}
>>        HashMap copy() {}
>> }
>>
>> ... And I've actually run into this problem.
> 
> Ok, but it will still work if Map.copy() is defined to return an Object
> rather than a Map. I concede it isn't as typesafe, in that whatever is
> derived from Object won't necessarilly be implementing Map, but it should
> work without ugly casting.

C'mon... Can't we do better than this?  And actually, it'll only work
without ugly casting if you're working with a HashMap:

Map!(char[], int) myMap = new HashMap!(char[],int)();
Map!(char[], int) originalMap = cast(Map!(char[],int)) myMap.clone();

The whole point of the interface, in this case, is to encourage people to
disconnect their code from the implemantation of the map; encourage them to
use the interface instead.

~John Demme



More information about the Digitalmars-d-dtl mailing list