Hello,
In the roadmap it is announced that Yii3 will follow best practive as SOLID :
“Be based on best practices such as SOLID, GRASP etc. and teach them to community.”
But, i’m following the dev of Yii3, and what I see is that there is a lot of attributes in new classes déclared as private, which, for me, completely breaks the Open Close Principle of SOLID.
"In object-oriented programming, the open/closed principle states “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification”;[1] that is, such an entity can allow its behaviour to be extended without modifying its source code. " (Wikipedia).
I think most of these must be declared protected to ensure SOLID compatibility. Is it planned?
Thank you
PS :
This is a repost from the Issue board (https://github.com/yiisoft/yii-core/issues/185).
I was answered this :
I think you’re misinterpreting open/closed principle. It is not about “make everything public/protected, so I can change everything”. It is about allowing to change one implementation by another, so you can use custom components without changing framework code. For example, you can freely change DB or URL manager components without editing a single Yii file. It already works pretty fine in Yii 2, and in Yii 3 should be even easier due to relying on DI and interfaces.
I never said Open/Close meant “make everything protected/public”, but Open Close is not about replacing or using custom components (i have no doubt this is the case), it is about extending and polymorphism.
Here is another part of the definition : " A module will be said to be open if it is still available for extension. For example, it should be possible to add fields to the data structures it contains, or new elements to the set of functions it performs."
How am I suppose to extend a class if most of it’s attributes are not accessible?