Open / Closed Principle

Open / Closed Principle

What is the Open / Closed Principle?

Definition: An object should be open for extension but closed for modification.

This principle states that code should only be modified to fix bugs and errors and to extend the functionality a new class should be used. Typically the new class would be a derived class to enable code re-use from the original or a common base class. This principle naturally leads to writing abstract base classes and extending functionality by writing new sub-classes.

Further reading on the Open / Closed Principle:

Bertrand Meyer

Finally, now you know about this Principle, read about the other SOLID principles of Object Orientated design here.

Leave a Comment

Your email address will not be published. Required fields are marked *