DEV Community

Discussion on: Open/Closed Principle

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent

While I understand the principle, I am unsure of what is the point of it. What are we trying to achieve following this principle? What is the benefit?

Collapse
 
satansdeer profile image
Maksim Ivanov

The point is to be able to extend system for cheap. So you won't have to make changes to your class/module every time you need to extend it. So this approach allows you to keep complexity low.

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent

Maybe i am missing something important here.

How does "not having to make changes to your classes" help to keep complexity low?

In the example you gave about the cookie machine, I would agree. It is a good way to extend the possibilities of the CookieMachine class, and it seems more flexible, but it actually seems to me like the complexity is bigger, than just adding a new "case".

Thread Thread
 
aportuguesedev profile image
João Franco • Edited

well, imagine that you are a technical guy and you are implementing a new feature on top of something that is already tested and is currently working. If you change the class that is already working, the probability that you introduce a bug with new developments is greater than if you just extend the class and implement the functionality that way. Although the complexity in both cases increases, because complexity of a system increases every time you add more stuff to it, your system isn't as interconnected as the way you were describing it.
This approach is called "Loose coupling" and you can search and read more about it if you're not familiar with it.

I realize this is an old post, but I'm a slow reader and adding my 2 cents for people like me who would be reading this and wondering about your points. :)