From This link Proxy are something like lazy loading, but how Magento 2 knows it needs to generate a proxy class and which class has a proxy ?
As you've probably noticed Magento 2 does not allow you to create an object without passing all dependencies. Proxies exist in case you have optional dependencies.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\GoogleAdwords\Observer\SetConversionValueObserver"> <arguments> <argument name="collection" xsi:type="object">Magento\Sales\Model\ResourceModel\Order\Collection\Proxy</argument> </arguments> </type> </config>
The file generated under
var/generation will extend the original class and its methods.
The important difference is the constructor which never calls the original constructor (you can get the details in the article you linked) which is what permits the defer loading.
Any class can have a proxy. Thanks to the Proxy keyword Magento will know it has to generate such class.