Magento2: Difference between Type and Virtual Type

Anshu Mishra
2 min readJul 17, 2021


  1. Virtual Types are the classes that are instantiated by the ObjectManager but have no physical / concrete class located in /app/code or in /generated.
  2. Type adjusts existing classes, whereas Virtual Types creates a new class.
  3. Type affect all the instances, whereas Virtual Type is equivalent of a sub class, where only the sub class has the altered argument values.
  4. Virtual Type must extend a concrete class type.
  5. To adjust the constructor parameters for an existing class, use the type declaration. These changes take effect for all class instantiations for that object in that area.
  6. To create an entirely new type of object that can be injected elsewhere use the virtual type declaration. You need to then inject or utilize this class in XML configuration (in di.xml or as a block).
  7. Virtual types are useful if the only necessary modifications to a class are the classes that are injected.
  8. You can’t reference the specific virtual type in a class’ constructor. Rather, your constructor should utilize the concrete class type the virtual type extends.
  9. You can’t write a class that inherits a virtual type.

You can read more on Type Configuration at
You can read more on Virtual Types at

I have collected these points from various sources on the internet while I was in initial stages of learning Magento2.
I hope these points will be helpful.



Anshu Mishra

I am Magento developer by profession. I like to play games and sports.