The Open/Closed Principle

The second SOLID principle concerns the extensibility of components and is called the Open/Closed Principle. Its focus is on avoiding changes when we need to extend a component's feature. The principle states:

Software entities like classes, modules and functions should be open for extension but closed for modifications.

In the design of the components of our application, we have to take into account these two aspects:

  • Open for extension: The components should be adjustable to the changing needs of the application
  • Closed for modifications: The required changes should not involve the original component itself

If we apply this principle, we can get more easily adaptable and maintainable applications.

To illustrate how to apply ...

Get Mastering JavaScript Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.