Talk:Avoid concrete base classes

From CSSEMediaWiki
Revision as of 11:15, 28 July 2008 by Chen Qing (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What’s wrong with the concrete base classes?

Some benefits of avoiding concrete base classes have been identified by others:

1.It gives more flexibility to the implementation.

In abstract base class, only the definitely needed methods will be introduced. This gives the maximum power for the child class to introduce new functionalities and implement its own behavior for a given functionality. In the case where a concrete base class is used, child class needs to overwrite the method defined in parent class if it is necessary. In cases where all the children classes need to overwrite a method provided by their concrete base class, then the implementation in the base class is almost obsolete, hence there shouldn’t be an implementation in the base class at all. For rapid development, it will be impossible to define a proper (concrete) method in the base class, hence abstract class is a better choice.

2.Minimize coupling relationships.

Use abstract base class rather than concrete class is good for minimizing coupling, the abstract base class itself is good for hiding the actual implementation.


However, I am still not fully convinced with this. If designed properly, inheritance also has a benefit in avoiding repeated code. If abstract base class is used heavily, as a result, there would be large section of repeated code. Regarding to the coupling issues, it is more of thinking base classes as interfaces, which only concerns one of the benefits inheritance could bring to us.

Should avoiding concrete base classes only be a good consideration rather than a ‘golden rule’? --Chen

Personal tools