Open Closed Principle (OCP)

Ibrahim Yilmaz
3 min readJun 8, 2020

In the O part of SOLID, I want to start again asserting. Now I want to assert that O is the most misunderstood design pattern and practise. Let’s understand it better in this article.

Photo by Coffee Geek on Unsplash

Let’s start with this definition(by Bertrand Meyer states):

software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification

I think that the cause of this misunderstood is this sentence.

Firstly, let’s misunderstand it together(Don’t say it in anywhere especially in Job Interviews, maybe you can meet one interviewer who knows this principle more than this xD):

open class OpenClosedClass{   fun method(){
println("OpenClosedClass:method")
}}

and we put class in a module and we use this module as a library. Now it is open for extension but closed for modifications!!!

PS:Don’t say it in anywhere especially in Job Interviews. Maybe you can meet one interviewer who knows this principle more than this xD.

After than hopefully Robert Martin joined the party and stated this:

You should be able to extend the behaviour of a system without having to modify that system.

--

--