Home » Blog

Magento 2 Esensial topics for Developer

Apr 9, 2019     5 min read

Dependency injection:

Dependency injection…..

Virtual types:

Virtual types are a way to inject different dependencies into existing classes without affecting other classes.

Reference - https://magento.stackexchange.com/a/33140/3368

types:

types lets us manipulate the dependencies injected to class constructors

Proxies:

Proxy classes use for lazy creation of object.

Proxy classes are intended to increase object creation speed. For example you want to create an object of the class where a lot of another classes are created in the constructor via dependency injection. Maybe you won’t use those classes but they are created and some of them can take some time to be created. To avoid such a scenario Proxy objects exists.

Reference - Recommend to read Magento 2 Object Manager: Proxy Objects

Factories:

Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

Reference - Illustration on Developer Docs

Plugins (interceptors):

A plugin, or interceptor, is a class that modifies the behavior of public class functions by intercepting a function call and running code before, after, or around that function call. This allows you to substitute or extend the behavior of original, public methods for any class or interface.

Reference - Illustration on Developer Docs