V. CONCLUSION
After learning the design patterns above, we get some
design principles:
Identify the aspects of your application that vary
and separate them from what stays the same.
Take the parts that vary and encapsulate them, so
that later you can alter or extend the parts that vary
without affecting those that don’t.
It forms the basis for almost every design pattern.
Program to an interface, not an implementation.
“Program to an interface” really means “Program to
a super type.”
The point is to exploit polymorphism by
programming to a super type so that the actual
runtime object isn’t locked into the code. And we
could rephrase “program to a super type” as “the
declared type of the variables should be a super type,
usually an abstract class or interface, so that the
objects assigned to those variables can be of any
concrete implementation of the super type, which
means the class declaring them doesn’t have to
know about the actual object types!”
Classes should be open for extension, but closed
for modification, which is the famous Open-
Close-Principle.
Creating systems using composition gives you a
lot more flexibility.
Not only does it let you encapsulate a family of
algorithms into their own set of classes, but it also
lets you change behavior at runtime as long as the
object you’re composing with implements the
correct behavior interface.