What is Open Closed Principle and give a brief description of Open Closed Principle with suitable examples?

What is Open Closed Principle and give a brief description of Open Closed Principle with suitable examples?

In object-oriented programming, the open–closed principle states “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification”; that is, such an entity can allow its behaviour to be extended without modifying its source code.

What is the Open Closed Principle in Java?

As the name suggests, this principle states that software entities should be open for extension, but closed for modification. As a result, when the business requirements change then the entity can be extended, but not modified.

Which is the best definition of the open closed principle?

The open/closed principle (OCP) states that a module should be open to extension but closed for modification. It is one of famous 5 solid principles and very important object oriented design principle. 1. Definition of open closed principle

Why did Robert C Martin redefined the open / closed principle?

That’s why Robert C. Martin and others redefined the Open/Closed Principle to the Polymorphic Open/Closed Principle. It uses interfaces instead of superclasses to allow different implementations which you can easily substitute without changing the code that uses them.

How is the open / closed principle used in refactoring?

Following the Open/Closed Principle, you need to extract an interface that enables you to control the coffee machine. That’s often the critical part of the refactoring. You need to include the methods that are mandatory for controlling the coffee machine, but none of the optional methods which would limit the flexibility of the implementations.

When did Bertrand Mayer define the open closed principle?

Bertrand Mayer, in his 1988 book, Object-Oriented Software Construction (Prentice Hall), defined the open/closed principle (OCP) as follows: Software entities should be open for extension, but closed for modification. 1.2. The Meyer definition