When to use inheritance?

I tend to ask those a lot :confused:

I think this is the problem I’m coming across, trying to make a composition solution from your inheritance… each controller would have to explicitely call handleRequest(), forward(), and execute() just to function like one that inherited from a parent controller, whereas with konstrukt, the controllers could be as simple as a GET() method.

Very true, though I haven’t seen a similar use of distributed routing like konstrukt… everyone seems to prefer central routing.

To put in my two cents, along with everybody else’s replies…

In addition to everything mentioned above, a lot of it is just down to common sense. What are you trying to accomplish in a given instance? Is it to truly extend something? As in a Person class being extended into EmployeePerson and ClientPerson? Or it is to make subsequent same-level children easier to implement?

As an example:

When writing my own applications I tend to wrap a data record type in a model that does nothing but maintain a set of data. That’s it. Validations are done by a seperate, dedicated class that acts on such a model. But I’ll have many models laying around and don’t want all that code duped. So I made an abstract base Model class. This class provides all the functionality that ALL my model-based classes will have.

So…

If you have two or more same-level classes that are based on a similar concept, by all means, abstract them to a base.

If you have a categorical need (this is-a that, and that is-a other thing) then by all means use inheritance.