Pointer to interface method

Mandel mandel at mailinator.com
Sun Apr 15 17:52:06 PDT 2007


Frits van Bommel Wrote:

> Mandel wrote:
> > Hi,
> > 
> > I like to have a pointer to an interface method,
> 
> What possible use could this have? Interface methods are by definition 
> abstract, and are thus never directly defined.
I want to call methods on objects that implement a specific interface.
In normal cases you would simple call the function by it's name and also by interface - trivial.

But it would also mean that I have to write code for every interface method class
implements and also every interface.
In my case I have many interfaces that may also change during development.
The behaviour on all functions is determined by their return type (it will be a RPC class). Therefore I would like to create a class that registers interface methods (passed as template argument).
This way, all code that handle objects based on a registered interface method
will be created at compile time.
No need for specific implementations for every interface in this case. :)

For example, if I have interfaces A, B, C, D and some classes that implement at least one of these interfaces. I have to write handler code (e.g. a class) for every interface.
If I would have a class that  allows to store (wrapped) accessors to interface methods,
only one class needs to be written - replacing all handler classes for each interface.

I hope I was not too confusing. ;-)

I have done this in C++. Would be nice if the same could be achieved in D.
> 
> (Note that D doesn't support the concept of a "member pointer" as C++ does)
Maybe there is something similar in D to achieve the same concept?




More information about the Digitalmars-d-learn mailing list