Plugins - is it bad habit to inherit from modified class in order to use protected properties

Plugin should not inherit modified class.

Also it's not recommended to inherit from non-abstract magento classes.


A Magento 2 plugin is:

Used to extend or modify a public method’s behavior by applying code before, after, or around that observed method.

If you're dealing with protected methods or properties then you cannot use plugins. Making your plugin class extends the original class is definitely not recommended at all.

The list of plugins limitations is available in the official documentation: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html

It depends on your needs, but if you need to change protected properties/methods, you should use preferences instead.

On top of that you could consider using observers depending on what you want to achieve exactly.

IMHO, here is the order in which you should choose your way of modifying core classes:

  1. Plugins
  2. If you cannot use plugins, observers
  3. If you cannot use plugins nor observers, use preferences