Open closed principle

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: The '''Open closed principle''' states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" as [http://www.objectmentor.com/res...)
 
Line 1: Line 1:
The '''Open closed principle''' states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" as [http://www.objectmentor.com/resources/articles/ocp.pdf 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.  
+
The '''Open closed principle''' states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" as [http://www.objectmentor.com/resources/articles/ocp.pdf 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.
 
This also prevents you from introducing new bugs in an existing code.

Revision as of 05:22, 29 July 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.

Personal tools