-
You should program to an interface, not an implementation of a class. This will lead to the code depending on abstractions and not concrete classes.
-
You can tell that the design is flexible enough if you can easily extend it without breaking any existing code.
-
There’s a flexible way to establish collaboration between objects:
- Determine what exactly one object needs from the other: which methods does it execute?
- Describe these methods in a new interface or abstract class
- Make the class that is a dependency implement this interface
- Make the second class dependent on this interface rather than on the concrete class