Interface segregation principle
We've already discussed the important role played by abstractions in object-oriented design. The abstractions and their derived classes without separation usually come up with hierarchical tree structures. That means when you choose to create a branch, you create a parallel abstraction to all of those on another branch.
For a family of classes with only one level of inheritance, this is not a problem: because it is just what you want to have those classes derived from. But for a hierarchy with greater depth, it could be.
Example
Consider the TextReader
example we took with Template Method Pattern in Chapter 6, Behavioral Design Patterns: Continuous we had FileAsciiTextReader
and HttpAsciiTextReader
derived from AsciiTextReader
. But what if we want to have other readers that understand UTF-8 encoding?
To achieve that goal, we have two common options: separate the interface into two for different objects that cooperate, or separate the interface into two then get...