# O - Open Closed (OCP)

## About

Classes should be open to extension and closed for modification.&#x20;

*The behavior of a module can be extended without modifying its source code.*

Whenever you need to add new functionality to a class, don't just modify the existent class.

Instead create a base class, and for each added functionality you make it in a new class to extend the base one.

{% hint style="info" %}
Using Factories to create similar implementations.
{% endhint %}

<img src="https://918994881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCohgIgtQvaflZD82x7YP%2Fuploads%2FeV0Q01OE8GNPnUvGyb2c%2Ffile.excalidraw.svg?alt=media&#x26;token=e17e1d51-a1a4-4d34-b4f7-54395cf5a95c" alt="" class="gitbook-drawing">
