Upload
webkul-software-pvt-ltd
View
64
Download
2
Embed Size (px)
Citation preview
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?