Re: Interface inheritance vs Implementation inheritance.
On 2008-02-20 00:15:44 -0600, Lasse Reichstein Nielsen <lrn@hotpop.com> said:
I wouldn't mind a language where implementation inheritance wasn't public,
i.e., your type only consists of interfaces. If you extend another class,
you also implements its interfaces, but the extended class is not part
of your type.
You mean like in C++?
class MyContainer : private SomeContainer {
....
}
And I would also like an easy way to create a composition, e.g.,
class Foo implements Bar(b) {
private Bar barbarbar implements Bar; // or delegates Bar
public Foo(int i) {
super(i);
this.barbarbar = new Bar(i);
}
//...
}
If you think about that a bit longer, you'll realize that an easy way
to create composition IS inheritance. Or rather, inheritance is an
easy way to create composition.
Every method of the component gets redeclared in the composer. When
those methods are called on the composer, the component's
implementation is invoked.
Now change the words composer to base, and component to derivative and
you'll see the sentence is true.
Perhaps what you are after is a way to make sure that the composer
cannot be cast (explicitly or implicitly) to the component. That's
what private inheritance gives you.
I conclude from this that we'd all be happy if Java had multiple
inheritance and private inheritance.
;-)
--
Robert C. Martin (Uncle Bob)??| email: unclebob@objectmentor.com
Object Mentor Inc.? ? ? ? ? ??| blog:??www.butunclebob.com
The Agile Transition Experts??| web:???www.objectmentor.com
800-338-6716? ? ? ? ? ? ? ? ??|