Thursday, 17 December 2015

Open Closed Principle

Software entities like classes, modules and functions should be open for extension but closed for modifications.
Open for Extension:
The behavior of the module can be extended. We can make the module behave in NEW and DIFFERENT ways as the requirements of the application change.
Closed for Modification:
The source code of such module is INVIOLATE. No one is allowed to make source code changes to it.
Abstaction is the Key. The following UML class diagrams picture this principle:
The Client class depends directly on the Server class. Extending Server implementations is difficult and further changes may introduce complexity in code maintainability.
The Client class now depends on an abstraction of the Service by the Service Base Class. We can extend further implementation from this abstraction.


Post a Comment