Open closed principle

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
This also prevents you from introducing new bugs in an existing code.
 
This also prevents you from introducing new bugs in an existing code.
 +
 +
== See also ==
 +
* [[Robert Cecil Martin 1996a]]

Revision as of 02:51, 20 August 2008

The Open closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" as Dr. Bertrand Meyer said. That means (in an ideal way...) you should never need to change existing code or classes.

So the idea was that once completed, the implementation of a class could only be modified to correct errors. So if you want to add new or changed features/functionalities, you would need to create a different class. That class could reuse coding from the original class through inheritance. The derived subclass might or might not have the same interface as the original class.

This also prevents you from introducing new bugs in an existing code.

See also

Personal tools