views:

169

answers:

3

I remember seeing a debate about this somewhere, and am currently considering removing a base object that every business object, in a system I'm working on, inherits from. It contains a few properties, some database logic, and some constructor logic.

Is this an anti pattern, or is the jury still out? Would it be better to have a base contract to inherit from, which would require a certain amount of boilerplate coding to be done in each object?

EDIT: I do like dsimcha and feel it reflects very well on the issue, I am still happy to hear any further answers

+1  A: 

The standard rule of thumb is to use inheritance only to provide flexibility for users of a class through polymorphism, and use composition if you want to reuse code from other classes. However, as long as you're not violating the Liskov Substitution Principle it's probably not too bad. Writing tons of boilerplate is inherently a bad thing, too, since it obscures the parts of your code where the real action is happening and is anti-DRY. If you are violating the Liskov Substitution Principle, though, then absolutely this is a bad idea.

dsimcha
Very good point - Liskov does appear to be a driving factor in the argument
johnc
+1  A: 

Nothing is an anti-pattern in a vacuum. Is your 'Eve class' causing you problems? What benefits do you expect to realize from removing it? Asking whether it's on some standard list of anti-patterns only helps if it aids in identifying actual issues.

chaos
true, but I also would like to understand what problems I may encounter, or should be aware of
johnc
+2  A: 

I also would like to understand what problems I may encounter, or should be aware of

A potential problem is if you use multiple inheritance: your subclass then inherits two instances of the 'Eve' classes ... which is why C++ supports so-called virtual inheritance.

It's a frequently-used idiom: for example in .Net everything derives from System.Object ... and/or, all COM objects implement the IQueryInterface interface.

ChrisW