Talk:Avoid concrete base classes

From CSSEMediaWiki
Revision as of 04:24, 2 September 2008 by Elliot Fisher (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


Chen I think you are getting confused about abstract classes - they are allowed to contain the implementation of methods, so you do not necessarily have to redefine the method in each child class. I'll explain this more tomorrow. --Elliot Fisher 04:24, 2 September 2008 (UTC)


--Added a brief start to the page, and explained that this rule only applies to inheritance hierarchies, as at first when I read the page title I was wondering why it should be applied to all classes including single classes with no inheritance. --Elliot Fisher 04:24, 2 September 2008 (UTC)

Personal tools