lundi 3 octobre 2022

Open-Closed Priciple: is this rephrasing correct?

I have spent a lot of time trying to understand the principle as it is stated. Read maybe several dozen articles "explaining" it, but it feels like everyone is just providing an example without actually specifying the ways that it works in our code in clear english language. The definition is understandable, what it actually means for our classes isn't.

I, maybe, gained a bit of understanding and I want to verify I am correct. Can it be rephrased like this?

Classes should be coded in such a way, that, given the initialization conditions of class instances do not change, any proposed behavioural extension cannot change the behaviour of old code.

Whether the proposed changes are achieved by inheritance or composition of differnt pointer of concrete type derived from an abstract interface we must change the type of the instance of the class we are modifying to a derived one, or pass a different interface implementation for any possible behavioural changes to take effect. Direct code fixes are not acceptable.

Is that it? Do I still not understand it?

Aucun commentaire:

Enregistrer un commentaire