Informal interfaces

Kristian kjkilpi at gmail.com
Mon Oct 2 04:22:00 PDT 2006


On Mon, 02 Oct 2006 11:42:43 +0300, Fredrik Olsson <peylow at gmail.com>  
wrote:
> An interface is a definition of what *must* be implemented.
> An informal interface is a definition of what *could* be implemented.
[snip]

I think informal interfaces would be good to have.


> A small price to pay, slightly more for non voids. Non default return
> values, anything different from type.init could be a problem, at least
> if no access to the original source. The value to use must be available
> somehow. I have though about letting the optional methods have dumy
> implementation returning the value, that could then be an expression and
> not a constant. But I think the testing for implemented methods would
> become more complex, and calling a method could be more costly that
> testing for NULL and branch, todays CPUs are good at branch prediction.

Hmm, if an interface would have a 'static vtable' containing addresses for  
the default functions (that return the default values), then the calling  
of functions could be done as follows:

1) Get the address of an function to be called to ADDR.
2) If ADDR is not null, goto case 4.
3) Get the address of the corresponding default function of the interface  
to ADDR.
4) Call the function pointed by ADDR.

(Of course, instead of using static table for function addresses, an  
interface could have a table pointing to the default values directly.)



More information about the Digitalmars-d mailing list