mercredi 25 mars 2015

Implementing common logic in base class


Background


In the documentation of a project I'm working on I came across the following sentence which immediately triggered an alarm for me:



when having several concrete classes that inherits from the same base class, logic which is common for all concrete classes should NOT be implemented in the base class.



This is a pretty bold statement which kind of conflicts with everything I think of OOP.


The reason stated was testability. It said that when writing unit tests, if a common logic is implemented in the base class, it will be tested multiple times for each concrete child and cannot be mocked out.


Question


Is this really true? If not can you give an example of how it can be mocked out? if it is what design patterns can I use to workaround this?





Aucun commentaire:

Enregistrer un commentaire