Magento Meetup New Delhi- Magento2 code generation

Post on 11-Feb-2017

57 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

Transcript

Magento2 Code Generation

BYAshutosh Srivastava

Basic questions that can explain

the concept ?

What is code generation ?

What is the need of code generation in magento2 ?

How code generation works ?

What is code

generation ?

code generation simply means the creation of non-existent classes automatically .

What is the need of code generation in magento2 ?

to facilitate DI(Dependency Injection) in magento2.

to facilitate plugin system in magento2.

fast class loading.

How Code Generation

Works?

Factory classesInterceptor

classesProxy classes

Factory Code

Generation

if a class is suffixed with factory and it is passed to the object manager or in the constructor and if the class is not existing then magento will create the class automatically.

Plugin Code Generation

if a plugin is defined in the di.xml, then its interceptor class is created in the var/generation .

Proxy Code Generation

since magento2 uses DI design pattern and you can pass the class reference in the constructor and when the class is loaded is starts a domino effect to overcome this problem magento2 uses proxy design pattern .

Benefits of Code

Generation

• don't need to write test cases for the generated classes

• fast class loading

• best solution for customization

• generalized approach

Thanks Questions?

top related