You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just a question, can you please explain why using protected is considered bad practice in Magento:
"WARNING | Use of protected class members is discouraged."
We're trying to prepare one extension for marketplace, and we deliberately used protected on few places to give other developers a chance to extend and change behavior of some classes if ever needed. If we change everything to private, any kind of class extensibility is harder to achieve.
I'm just not sure if discouraging protected is a good idea, they have their own purpose, so we would like to know logic behind this so we could follow best practices better :)
Thanks, Ivan
The text was updated successfully, but these errors were encountered:
So instead of using protected methods, split this functionality into a different class and inject it. Then it will be easier to override this functionality via plugins, because this separate class still needs to expose at least 1 public method. Preferences are not preferable because they suffer from same issues as M1's rewrites.
Another thing worth mentioning is that these are specifically marked as warnings rather than errors. It's almost impossible to create extensions that don't make use of protected properties/methods because of the state of the Magento core itself.
Uh oh!
There was an error while loading. Please reload this page.
Hello Magento,
Just a question, can you please explain why using protected is considered bad practice in Magento:
"WARNING | Use of protected class members is discouraged."
We're trying to prepare one extension for marketplace, and we deliberately used protected on few places to give other developers a chance to extend and change behavior of some classes if ever needed. If we change everything to private, any kind of class extensibility is harder to achieve.
I'm just not sure if discouraging protected is a good idea, they have their own purpose, so we would like to know logic behind this so we could follow best practices better :)
Thanks, Ivan
The text was updated successfully, but these errors were encountered: