Why not finally allow bracket-less top-level keywords?

F i L witte2008 at gmail.com
Mon Mar 19 10:41:16 PDT 2012


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.




More information about the Digitalmars-d mailing list