Tuesday, September 25, 2007

Removing by not adding

When creating subclasses, there are chances that we want to remove some inherited operations/fields. This requirement appears more frequently when dealing with multiple inheritance. Why doesn't Java (or any other OO languages) provide a facility that does such removal? Because it is evil. This removal facility will rapidly create unmanageable code because no operation in a class is guaranteed to exist.

Then how do we deal with this case using OO paradigm? Well, if such requirement arises, it normally implies a bad design! We should decompose super-classes/interfaces (break into pieces), group those operations that we wanted to remove, and just not add corresponding classes/interfaces as super types.

No comments: