Open Closed Principle

2023-03-26  本文已影响0人  kkjusdoit
image.png
image.png
image.png
image.png
image.png

Open-Closed Principle in C#

Implementation Guidelines for Open-Closed Principle (OCP) using C#

  1. The easiest way to implement the Open-Closed Principle in C# is to add new functionalities by creating new derived classes which should be inherited from the original base class.
  2. Another way is to allow the client to access the original class with an abstract interface.

So, at any given point in time when there is a change in requirement or any new requirement comes then instead of touching the existing functionality, it’s always better and suggested to **create new derived classes ** and leave the original class implementation as it is.

上一篇 下一篇

猜你喜欢

热点阅读