Open/Closed Principle
The Open/Closed Principle states that classes should be open to extension, but closed to
modification. This means that future developers working on the system should not be allowed or
encouraged to modify the source of existing classes, but instead find ways to extend the existing
classes to provide new functionality.
The Strategy Pattern introduced in the previous chapter of
Design Patterns
provides a great
example of how the Open/Closed Principle works. In it, we defined strategies for mechanisms to
deliver invoices to customers. If we wanted to add a new delivery method, perhaps one via an
EDI (Electronic Data Interchange), we could simply write a new adapter:
Do'stlaringiz bilan baham: |