On Wed, Nov 25, 2009 at 4:48 AM, Duncan Pearson <
ma...@duncanpearson.net> wrote:
> If I wish a type to implement two interfaces developed independently,
> and if there is a method in one interface for which a method with the
> same name exists in the other interface then I potentially have a
> problem.
Does ANY language have an explicit mechanism allowing one object to
satisfy two different interfaces that expect one method to do two
different things? Java and C++ certianly do not.
And wait a minute, Is there any plausible, practical reason it has to
all fit in ONE object? Just write two objects.
> A related problem is that in a system under development, in which the
> definitions of interfaces might change, I have no way of ensuring that
> a type implements a given interface as the compiler does not know that
> it is intended to. It is not until an instance of the type is used for
> an instance of the interface that the compiler will check.
You WILL get a compiler error if you try to assign a concrete data
type directly to an interface it does not satisfy. It's only a runtime
error if you're doing fancy tricks with the empty interface, and then
you deserve what you get.
> Would it be possible to have an interface implementation declaration
> for a type.
Of course it's "possible" to re-implement java, but we already have Java.
> If so might it be possible to augment this with a map from
> the names of any interface functions to the functions (or names of the
> functions) that implement them. (...)
> e.g.
>
> implementation MyType ; Interface1 {
> foo : myFoo;
> goo : myGoo
> }
Not even C++ has implemented such a baroquely over-engineered solution
to the fundamentally social problem of development teams not talking
to each other, and their implementation of templates are Turing
complete.
And really, it isn't any SIMPLER than just writing another object that
implements the interface. In fact, if it was implemented at all (and I
hope it isn't) it would probably just be syntactic sugar for
boiler-plate code you could write yourself:
func (p *MyType_Interface1) foo() { p.myFoo(); }