Difference between plugin and preference in Magento 2.x

Both Plugins and Preferences are used to override the classes. However, Plugins are preferable than Preferences since plugins do not override the class logically instead it hooks our logic into the available classes. Finally, to modify or extend any existing business logic, it is better to use the plugins.

Preference is used for overriding class & Plugin is used for adding functionality before, after and around methods by using function call or set of code.

“Always prefer Plugin over Preference , while overriding or modify class”

Leave a Reply

Your email address will not be published. Required fields are marked *