Should you beware of the utility base class?
What do you think about a base class that doesn’t
offer any business value to an object, but provide services? By that I mean a
base class that takes care of persistence, validation, etc.
I just run into a situation where I’ve such a class, but
I don’t want some of my classes to use it. The problem is that this
happens in the middle of the hierarchy. Here is the scenario:
- Rule – Persisted to database
- Built-in Rule – Not persisted to database
- Lots of Rules – Persisted to database
Rule inherits from a base class that handles the persistence.
Most of the rules are persisted, but the built in ones always exist. What I needed was a way to do multiply
inheritance, so I could have this hierarchy:
- Rule – Not persisted, provide common interface and
services
- Built-in Rules – Not persisted.
- Persisted Rule – Inherits from Rule and the persistence
class
- Lots of rules
You can’t do that in .Net (which is a shame).
Right now I’ve a situation where a built in rule looks like it can be persisted, which I
don’t want to happen. Any suggestions?
Comments
Comment preview