Should concrete classes avoid calling other concrete classes, except for data objects?
Posted
by
Kazark
on Programmers
See other posts from Programmers
or by Kazark
Published on 2012-09-14T17:30:36Z
Indexed on
2012/09/14
21:47 UTC
Read the original article
Hit count: 254
In Appendix A to The Art of Unit Testing, Roy Osherove, speaking about ways to write testable code from the start, says,
An abstract class shouldn't call concrete classes, and concerete classes shouldn't call concrete classes either, unless they're data objects (objects holding data, with no behavior). (259)
The first half of the sentence is simply Dependency Inversion from SOLID. The second half seems rather extreme to me. That means that every time I'm going to write a class that isn't a simple data structure, which is most classes, I should write an interface or abstract class first, right? Is it really worthwhile to go that far in defining abstract classes an interfaces? Can anyone explain why in more detail, or refute it in spite of its benefit for testability?
© Programmers or respective owner