Open Closed Principle: software should be open for extension but closed for modification. When new functionality is needed:
- Keep existing modules, classes, etc as they are
- Extend existing interfaces and classes to provide new functionality
Example Problem: say we have some OrderReport class which creates invoices from a list of orders, we now want to add a bill class which also includes an address in the document. We have no way to guarantee the address will be there, or otherwise we will always need it even if we are only creating invoices which don’t need this. Instead, we can make OrderReport only contain the list of orders. And then use this within the Invoice or Bill class in addition to any other information we have in order to generate the document. This is similar to the Strategy (Design Pattern).