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”

3 thoughts on “Difference between plugin and preference in Magento 2.x

  1. Good day very cool site!! Man .. Beautiful ..
    Superb .. I’ll bookmark your site and take the feeds additionally?
    I am glad to find so many helpful info here within the put up, we’d like work out extra strategies
    on this regard, thanks for sharing. . . . . .

  2. I’m extremely impressed with your writing skills as well as with
    the layout on your weblog. Is this a paid theme or
    did you customize it yourself? Anyway keep up the
    excellent quality writing, it’s rare to see a great
    blog like this one today.

Leave a Reply

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