What is difference on both and how will i understand to where should i use any one of these ?



if i use


In constructor then.

3 Answers 3


There is no difference between use of ObjectManagerInterface and ObjectManager class. As When you use ObjectManagerInterface it will give instance of ObjectManager class.


But You should never use ObjectManager directly in the code. It will Automatically come in use when we specify Factory Classes in constructor.

If due to some application constraints, you need to use ObjectManager then use ObjectManagerInterface in constructor.


First you must know what are interfaces?

  • Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’

  • Interfaces cannot be instantiated – they are a construct in OOP that allows you to inject ‘qualities’ into classes .. like abstract classes.

  • Where an abstract class can have both empty and working/concrete methods, interface methods must all be shells – that is to say, it must be left to the class (using the interface) to flesh out the methods.

Below reference will guide when to use interface and when to direct class.

when and why you should use them instead of classes


Using in constructor is a better choice then the other way, as you are injecting it into the class.

The other way is also used but it is not good. I use the other way only when i am overriding a class which has many injected classes, so if i inject my new class in the child class then i have to override the contructor of parent class. which means i have to inject all classes in parent also in classed and call the parent class. So to avoid this i use object mangener.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.