DigestCPP

Lets Understand With Example

  • Home
  • Design Principal
  • Design Patterns
  • C++ 11 Features
  • C++11 Multithreading
  • Contact Us

Open and Close Principle

Definition

It defines that our design or code should be open for extension but close for modification. In other word, open for extension means: when we create new base class then we need to design this base class such as way that it can be extended easily by just adding new derive class. Close for modification means: we should not disturb the existing code for any new feature. If we are changing in existing class then our design is not good.

If we can support new feature just adding new derive class and we are not touching existing class then our design is following (OCP).

 

Class diagram:

source code with example:

Output:

Primary Sidebar




DigestCPP © 2023. All rights reserved.

    About Privacy Policy Terms and Conditions Contact Us Disclaimer