Sitemap
Better Programming

Advice for programmers.

Do You Use the Most Crucial Principle of Object-Oriented Design?

The open-closed principle in action

6 min readMar 17, 2020

--

Press enter or click to view image in full size
Photo by Nick Fewings on Unsplash

The most crucial principle of object-oriented design is the The open-closed principle (OCP).

It took me a while to understand the the OCP. I found the contradiction “modules should be both open and closed” vague.

It wasn’t until after I read “Refactoring: Improving the Design of Existing Code” from Martin Fowler that it all started to make sense.

In this article, I’ll describe my point of view on the OCP. I’ll use two real-world examples — one from a previous project and another from an open-source project on GitHub.

I’ll end by sharing some heuristics to detect source code you can improve using the OCP.

The Definition of the OCP

A bit of history:

The OCP is one of the five principles that Bertrand Meyer described in 1988 in his book “Object-Oriented Software Construction.” These five principles of software construction describe how to create a modular system using object-oriented concepts.

In the book, Bertrand described the OCP as:

“Modules should be both open and closed.
• A module is said to be open if it is still available for…

--

--

Patrick Kalkman
Patrick Kalkman

Written by Patrick Kalkman

IT Architect, Developer & Writer focused on open-source, AI, LLMs & AI agents. Embracing agile methodologies, lifelong learning, and knowledge sharing.

Responses (2)