Le 19/03/2012 18:41, F i L a écrit :
deadalnix wrote:
It looks like a bad usage of inheritance. If you want to use these
methods, why not use composition ?
It make no sense to use such an inherited class in a polymorphic
context, so why use inheritance at all ?
Am I missing something about what you're saying? Having a final
class is completely different than locking up it's functions:
abstruct class Actor
{
void create() {}
void update() {}
}
class Ship : Actor
{
final void create() {}
final void update() {}
final void fire() {}
}
class MotherShip : Ship
{
final void fireMissle() {}
}
void main() {
Actor[] actors = [
new Ship();
new MotherShip();
];
foreach (actor; actors) {
actor.fire();
}
}
If Ship was final simply because all it's methods where, then you
couldn't inherit it's functionality into MotherShip.
That is totally broken design. The fact that mothership inherit from
ship is a pretty good example of misusing inheritance. The fireMissle is
useless unless you KNOW that you are manipulating a MotherShip, so you
totally break all the abstraction the OOP could provide.