{"id":64036,"date":"2016-11-12T18:12:04","date_gmt":"2016-11-12T18:12:04","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=64036"},"modified":"2025-12-31T14:00:23","modified_gmt":"2025-12-31T14:00:23","slug":"magento2-proxy-design-pattern-code-generation","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/","title":{"rendered":"Magento2 Proxy Design Pattern And Code Generation"},"content":{"rendered":"\n<p>Magento 2 uses the <strong>Proxy design pattern<\/strong> to improve system performance. It helps manage heavy objects that consume high memory. The system creates a &#8220;placeholder&#8221; instead of the real object. This ensures that Magento only initializes expensive classes when they are actually needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Proxy?<\/h2>\n\n\n\n<p>A Proxy is a class that replaces another class. It shares the same interface as the original object. Magento generates these classes automatically during the code compilation process. By using proxies, you prevent unnecessary object instantiation during the bootstrap phase.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Proxies in Magento 2?<\/h2>\n\n\n\n<p>Most Magento 2 classes use <strong>Constructor Injection<\/strong>. If a class has ten dependencies, Magento loads all ten immediately. Some dependencies might be &#8220;heavy&#8221; or rarely used. A Proxy stops this &#8220;chain reaction&#8221; of loading, which speeds up your application significantly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the proxy design pattern ?<\/h2>\n\n\n\n<p>The <strong>Magento 2 Proxy Design Pattern<\/strong> is a structural design pattern. It works as a placeholder for another object. The real object is created only when it is actually required. This approach is known as lazy loading. Magento uses proxies to avoid heavy object initialization during class construction.<\/p>\n\n\n\n<p>Lets understand why this problem comes in magento2.<\/p>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>Magento 2 supports multiple types of dependency injection, with constructor injection and method injection used most frequently.<\/p>\n\n\n\n<p>Constructor injection introduces a performance issue. When a class is instantiated, Magento immediately creates all objects injected into its constructor.<\/p>\n\n\n\n<p>This behavior triggers a chain reaction where Magento creates multiple dependent objects at once. As the number of dependencies increases, the instantiation process becomes slower and resource-intensive.<\/p>\n\n\n\n<p>To prevent this chain reaction and improve performance, Magento uses the Proxy Design Pattern, which enables lazy loading of dependencies.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>Magento solves this performance problem by using the Proxy Design Pattern.<\/p>\n\n\n\n<p>Instead of creating all dependencies during class instantiation, Magento injects a proxy class into the constructor. The proxy acts as a placeholder for the actual dependency. Magento creates the real object only when the code actually uses it.<\/p>\n\n\n\n<p>This approach delays object creation and avoids unnecessary instantiation. As a result, Magento reduces memory usage and improves overall performance.<\/p>\n\n\n\n<p>The Proxy Design Pattern enables lazy loading while keeping constructor injection clean and maintainable. <br>Example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\"> &lt;type name=&quot;Magento\\Catalog\\Model\\Product&quot;&gt;\n    &lt;arguments&gt;\n        &lt;argument name=&quot;catalogProductStatus&quot; xsi:type=&quot;object&quot;&gt;\n             Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status\\Proxy\n        &lt;\/argument&gt;\n\n        &lt;argument name=&quot;productLink&quot; xsi:type=&quot;object&quot;&gt;\n             Magento\\Catalog\\Model\\Product\\Link\\Proxy\n        &lt;\/argument&gt;\n    &lt;\/arguments&gt;\n&lt;\/type&gt;<\/pre>\n\n\n\n<p>The above entry comes from the <strong>Catalog module\u2019s <code>di.xml<\/code><\/strong> file.<br>In the <code>type<\/code> declaration for the <code>Magento\\Catalog\\Model\\Product<\/code> class, Magento replaces the constructor arguments <code>catalogProductStatus<\/code> and <code>productLink<\/code> with their corresponding <strong>Proxy classes<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status\\Proxy<\/code><\/li>\n\n\n\n<li><code>Magento\\Catalog\\Model\\Product\\Link\\Proxy<\/code><\/li>\n<\/ul>\n\n\n\n<p>Both classes include the word <strong>Proxy<\/strong>, which indicates the use of the <strong>Proxy Design Pattern<\/strong>. You will not find these proxy classes in the Magento 2 codebase after installation.<\/p>\n\n\n\n<p>Magento generates these proxy classes automatically using its code generation system.<br>The system creates proxy classes in two situations.<\/p>\n\n\n\n<p><strong>First<\/strong>, when you run the CLI command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\nphp bin\/magento setup:di:compile<\/pre>\n\n\n\n<p>Magento scans all <code>di.xml<\/code> files across installed modules.<br>If it finds a reference to a Proxy class that does not exist, it generates the class automatically inside the <code>generated\/code<\/code> directory with the same namespace.<\/p>\n\n\n\n<p><strong>Second<\/strong>, when Magento requests a Proxy class at runtime and the class does not exist, it does not throw an error.<br>Instead, Magento dynamically generates the Proxy class inside the <code>generated\/code<\/code> directory and returns its object.<\/p>\n\n\n\n<p>This mechanism shows that Magento generates proxy classes on demand using a fixed convention.<br>Magento replaces the original object with its Proxy, but the key question remains: <strong>how does the Proxy solve the performance problem?<\/strong><\/p>\n\n\n\n<p>To understand this, we need to analyze a generated Proxy class.<br>Let\u2019s look at the Proxy class next.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status;\n\n\/**\n * Proxy class for @see \\Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status\n *\/\nclass Proxy extends \\Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status implements \\Magento\\Framework\\ObjectManager\\NoninterceptableInterface\n{\n    \/**\n     * Object Manager instance\n     *\n     * @var \\Magento\\Framework\\ObjectManagerInterface\n     *\/\n    protected $_objectManager = null;\n\n    \/**\n     * Proxied instance name\n     *\n     * @var string\n     *\/\n    protected $_instanceName = null;\n\n    \/**\n     * Proxied instance\n     *\n     * @var \\Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status\n     *\/\n    protected $_subject = null;\n\n    \/**\n     * Instance shareability flag\n     *\n     * @var bool\n     *\/\n    protected $_isShared = null;\n\n    \/**\n     * Proxy constructor\n     *\n     * @param \\Magento\\Framework\\ObjectManagerInterface $objectManager\n     * @param string $instanceName\n     * @param bool $shared\n     *\/\n    public function __construct(\\Magento\\Framework\\ObjectManagerInterface $objectManager, $instanceName = '\\\\Magento\\\\Catalog\\\\Model\\\\Product\\\\Attribute\\\\Source\\\\Status', $shared = true)\n    {\n        $this->_objectManager = $objectManager;\n        $this->_instanceName = $instanceName;\n        $this->_isShared = $shared;\n    }\n\n    \/**\n     * @return array\n     *\/\n    public function __sleep()\n    {\n        return ['_subject', '_isShared', '_instanceName'];\n    }\n\n    \/**\n     * Retrieve ObjectManager from global scope\n     *\/\n    public function __wakeup()\n    {\n        $this->_objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n    }\n\n    \/**\n     * Clone proxied instance\n     *\/\n    public function __clone()\n    {\n        $this->_subject = clone $this->_getSubject();\n    }\n\n    \/**\n     * Get proxied instance\n     *\n     * @return \\Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status\n     *\/\n    protected function _getSubject()\n    {\n        if (!$this->_subject) {\n            $this->_subject = true === $this->_isShared\n                ? $this->_objectManager->get($this->_instanceName)\n                : $this->_objectManager->create($this->_instanceName);\n        }\n        return $this->_subject;\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getVisibleStatusIds()\n    {\n        return $this->_getSubject()->getVisibleStatusIds();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getSaleableStatusIds()\n    {\n        return $this->_getSubject()->getSaleableStatusIds();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getAllOptions()\n    {\n        return $this->_getSubject()->getAllOptions();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getOptionText($optionId)\n    {\n        return $this->_getSubject()->getOptionText($optionId);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function addValueSortToCollection($collection, $dir = 'asc')\n    {\n        return $this->_getSubject()->addValueSortToCollection($collection, $dir);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function setAttribute($attribute)\n    {\n        return $this->_getSubject()->setAttribute($attribute);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getAttribute()\n    {\n        return $this->_getSubject()->getAttribute();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getOptionId($value)\n    {\n        return $this->_getSubject()->getOptionId($value);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getFlatColumns()\n    {\n        return $this->_getSubject()->getFlatColumns();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getFlatIndexes()\n    {\n        return $this->_getSubject()->getFlatIndexes();\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getFlatUpdateSelect($store)\n    {\n        return $this->_getSubject()->getFlatUpdateSelect($store);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getIndexOptionText($value)\n    {\n        return $this->_getSubject()->getIndexOptionText($value);\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function toOptionArray()\n    {\n        return $this->_getSubject()->toOptionArray();\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding the Proxy Class in Magento 2<\/h3>\n\n\n\n<p>A Proxy class follows a strict structure to replace the original class efficiently.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <strong>namespace of the Proxy class<\/strong> matches the original class<br>(<code>Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status<\/code>).<br>This allows Magento to seamlessly substitute the original object with the Proxy.<\/li>\n\n\n\n<li>The <strong>Proxy class extends the original class<\/strong>, so it can access all public methods without breaking functionality.<\/li>\n\n\n\n<li>The Proxy implements <code>\\Magento\\Framework\\ObjectManager\\NoninterceptableInterface<\/code>.<br>This marker interface prevents plugins from intercepting the Proxy class.<\/li>\n\n\n\n<li>The <strong>constructor is the most important part<\/strong>. It injects only the <code>ObjectManager<\/code>, not the full dependency chain. This makes the Proxy lightweight and fast to instantiate. The constructor does <strong>not call the parent constructor<\/strong>, which avoids unnecessary object creation.<\/li>\n\n\n\n<li>PHP magic methods like <code>__sleep<\/code>, <code>__wakeup<\/code>, and <code>__clone<\/code> manage serialization and cloning behavior safely.<\/li>\n\n\n\n<li>The <code>_getSubject()<\/code> method creates and returns the <strong>original class object only when needed<\/strong>. This enables <strong>lazy loading<\/strong> and delays heavy object creation.<\/li>\n\n\n\n<li>All public methods from the original class are <strong>overridden<\/strong> in the Proxy. Each method calls <code>_getSubject()<\/code> and then delegates execution to the real object.<\/li>\n<\/ul>\n\n\n\n<p>In short, the Proxy class delays object creation until required, reducing memory usage and improving Magento 2 performance.<\/p>\n\n\n\n<p>For technical assistance, please get in touch with us via email at&nbsp;<a href=\"mailto:support@webkul.com\" target=\"_blank\" rel=\"noreferrer noopener\">support@webkul.com<\/a>.<\/p>\n\n\n\n<p>Discover powerful solutions to enhance your Magento 2 store by exploring our&nbsp;<a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Magento 2 plugins<\/a>&nbsp;page.<\/p>\n\n\n\n<p>Bring your vision to life with custom-built solutions\u2014hire skilled\u00a0<a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">Magento 2 developers<\/a>\u00a0today.<br>Happy Coding!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 uses the Proxy design pattern to improve system performance. It helps manage heavy objects that consume high memory. The system creates a &#8220;placeholder&#8221; instead of the real object. This ensures that Magento only initializes expensive classes when they are actually needed. What is a Proxy? A Proxy is a class that replaces another <a href=\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":33,"featured_media":61510,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,1],"tags":[],"class_list":["post-64036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento2 Proxy Design Pattern And Code Generation<\/title>\n<meta name=\"description\" content=\"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento2 Proxy Design Pattern And Code Generation\" \/>\n<meta property=\"og:description\" content=\"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-12T18:12:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-31T14:00:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashutosh Srivastava\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashutosh Srivastava\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\"},\"author\":{\"name\":\"Ashutosh Srivastava\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\"},\"headline\":\"Magento2 Proxy Design Pattern And Code Generation\",\"datePublished\":\"2016-11-12T18:12:04+00:00\",\"dateModified\":\"2025-12-31T14:00:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\"},\"wordCount\":797,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\",\"name\":\"Magento2 Proxy Design Pattern And Code Generation\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-11-12T18:12:04+00:00\",\"dateModified\":\"2025-12-31T14:00:23+00:00\",\"description\":\"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260,\"caption\":\"Ui Component Form\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento2 Proxy Design Pattern And Code Generation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\",\"name\":\"Ashutosh Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashutosh Srivastava\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/ashutosh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento2 Proxy Design Pattern And Code Generation","description":"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/","og_locale":"en_US","og_type":"article","og_title":"Magento2 Proxy Design Pattern And Code Generation","og_description":"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.","og_url":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-11-12T18:12:04+00:00","article_modified_time":"2025-12-31T14:00:23+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Ashutosh Srivastava","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashutosh Srivastava","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/"},"author":{"name":"Ashutosh Srivastava","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970"},"headline":"Magento2 Proxy Design Pattern And Code Generation","datePublished":"2016-11-12T18:12:04+00:00","dateModified":"2025-12-31T14:00:23+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/"},"wordCount":797,"commentCount":10,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/","url":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/","name":"Magento2 Proxy Design Pattern And Code Generation","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","datePublished":"2016-11-12T18:12:04+00:00","dateModified":"2025-12-31T14:00:23+00:00","description":"Learn how Magento 2 uses the Proxy Design Pattern to optimize dependency injection, prevent heavy object creation, and improve performance.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","width":825,"height":260,"caption":"Ui Component Form"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento2-proxy-design-pattern-code-generation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento2 Proxy Design Pattern And Code Generation"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970","name":"Ashutosh Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashutosh Srivastava"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/ashutosh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/64036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=64036"}],"version-history":[{"count":17,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/64036\/revisions"}],"predecessor-version":[{"id":519776,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/64036\/revisions\/519776"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/61510"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=64036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=64036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=64036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}