Why are interfaces so restrictive?

BCS BCS_member at pathlink.com
Sat Mar 18 09:46:22 PST 2006


In article <dvh9mr$2nbc$1 at digitaldaemon.com>, Jarrett Billingsley says...
>
>"BCS" <BCS_member at pathlink.com> wrote in message 
>news:dvfqn0$470$1 at digitaldaemon.com...
>> No it wouldn't (if my understanding of interfaces is correct) all that it 
>> would require is the generation of the function pointer table at compile 
>> time and at run time, the joining of that pointer and a pointer to the 
>> struct.
>
>It might be possible, but it would involve making a "second" kind of 
>inheritance that wouldn't really fit into the current class and interface 
>inheritance method.

Why do we say a class "inherits" from an interface? The only thing it 
gets is a set of mandatory function signatures and a way of passing 
them around. Wouldn't it be better to say that something "Implements" an
interface?

I guess my point is that allowing for the use of interfaces with other 
things would have some benefits and shouldn't, IMHO, have much cost.


>
>> That might work, however, it requires allocating a class and a more 
>> complicated call/access sequence. Either [#1] the class has to have 
>> access to the local stack frame (by storing a pointer to it and 
>> adding another level of indirection) or [#2] the data in the class 
>> needs to be available to the function (again by way of a pointer). 
>> Nether of these is desirable and the same effect can be had (with 
>> less cost) by using my idea.
>
>It can.
>

Yep, I agree that would work, however that is method #1 from above, and the
access to the array is by way of a pointer stored in the object.

>void Foo()
>{
> Item[char[]] bar;
>
> Database db = new class Database
> {
>  Item SearchForItem(char[] n)
>  {
>   if(n in bar)
>    return bar[n];
>   throw new Error("blah!");
>
>  }
>
>  bool AddItem(char[] n, Item i)
>  {
>   if(n in bar)
>    throw new Error("blah!");
>
>   bar[n] = i;
>   return true;
>  }
>
>  bool RemoveItem(char[] n)
>  {
>   if(n in bar)
>   {
>    bar.remove(n);
>    return true;
>   }
>
>   throw new Error("blah!");
>  }
> };
>
> DatabaseUI(db);
>}
>
>This looks strikingly like what you originally posted. 
>
>





More information about the Digitalmars-d mailing list