What is difference on both Object manager?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
What is difference on both and how will i understand to where should i use any one of these ?
MagentoFrameworkObjectManagerInterface
MagentoFrameworkAppObjectManager::getInstance()
if i use
MagentoFrameworkAppObjectManager
In constructor then.
magento2 object-manager
add a comment |Â
up vote
3
down vote
favorite
What is difference on both and how will i understand to where should i use any one of these ?
MagentoFrameworkObjectManagerInterface
MagentoFrameworkAppObjectManager::getInstance()
if i use
MagentoFrameworkAppObjectManager
In constructor then.
magento2 object-manager
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
What is difference on both and how will i understand to where should i use any one of these ?
MagentoFrameworkObjectManagerInterface
MagentoFrameworkAppObjectManager::getInstance()
if i use
MagentoFrameworkAppObjectManager
In constructor then.
magento2 object-manager
What is difference on both and how will i understand to where should i use any one of these ?
MagentoFrameworkObjectManagerInterface
MagentoFrameworkAppObjectManager::getInstance()
if i use
MagentoFrameworkAppObjectManager
In constructor then.
magento2 object-manager
magento2 object-manager
asked Aug 29 at 6:09
Ansar Husain
1,463217
1,463217
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
3
down vote
accepted
There is no difference between use of ObjectManagerInterface
and ObjectManager
class. As When you use ObjectManagerInterface
it will give instance of ObjectManager
class.
MagentoFrameworkAppObjectManager
MagentoFrameworkObjectManagerInterface
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.
add a comment |Â
up vote
6
down vote
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
add a comment |Â
up vote
1
down vote
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.
add a comment |Â
up vote
1
down vote
You should use the interface
MagentoFrameworkObjectManagerInterface
as Magento has mechanism called Dependency injection. This is originally provided by symfony/dependency-injection
package - look it up in your composer.lock file.
In effect the dependency injection mechanism will locate that actual class that implements the given interface. You need not to worry which is the actual class that gets instantiated.
For example, each module will define a preference for a given interface.
Lets take a look at file /vendor/magento/module-wishlist/etc/di.xml
There is a code like
<preference for="MagentoWishlistModelAuthenticationStateInterface" type="MagentoWishlistModelAuthenticationState" />
which means that if you try to inject MagentoWishlistModelAuthenticationStateInterface
in some of your class, Magento will make sure you get instance of MagentoWishlistModelAuthenticationState
And if for some reason you are not happy with the default class used, you can always tell magento to use another class in you module /etc/di.xml
file.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
There is no difference between use of ObjectManagerInterface
and ObjectManager
class. As When you use ObjectManagerInterface
it will give instance of ObjectManager
class.
MagentoFrameworkAppObjectManager
MagentoFrameworkObjectManagerInterface
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.
add a comment |Â
up vote
3
down vote
accepted
There is no difference between use of ObjectManagerInterface
and ObjectManager
class. As When you use ObjectManagerInterface
it will give instance of ObjectManager
class.
MagentoFrameworkAppObjectManager
MagentoFrameworkObjectManagerInterface
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.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
There is no difference between use of ObjectManagerInterface
and ObjectManager
class. As When you use ObjectManagerInterface
it will give instance of ObjectManager
class.
MagentoFrameworkAppObjectManager
MagentoFrameworkObjectManagerInterface
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.
There is no difference between use of ObjectManagerInterface
and ObjectManager
class. As When you use ObjectManagerInterface
it will give instance of ObjectManager
class.
MagentoFrameworkAppObjectManager
MagentoFrameworkObjectManagerInterface
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.
edited Aug 29 at 7:08
answered Aug 29 at 6:33
Pankaj Pareek
2,21211235
2,21211235
add a comment |Â
add a comment |Â
up vote
6
down vote
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
add a comment |Â
up vote
6
down vote
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
add a comment |Â
up vote
6
down vote
up vote
6
down vote
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
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
edited Aug 29 at 6:54
answered Aug 29 at 6:35
Qaisar Satti
25.1k1154100
25.1k1154100
add a comment |Â
add a comment |Â
up vote
1
down vote
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.
add a comment |Â
up vote
1
down vote
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.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
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.
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.
answered Aug 29 at 6:34
Avesh Naik
19712
19712
add a comment |Â
add a comment |Â
up vote
1
down vote
You should use the interface
MagentoFrameworkObjectManagerInterface
as Magento has mechanism called Dependency injection. This is originally provided by symfony/dependency-injection
package - look it up in your composer.lock file.
In effect the dependency injection mechanism will locate that actual class that implements the given interface. You need not to worry which is the actual class that gets instantiated.
For example, each module will define a preference for a given interface.
Lets take a look at file /vendor/magento/module-wishlist/etc/di.xml
There is a code like
<preference for="MagentoWishlistModelAuthenticationStateInterface" type="MagentoWishlistModelAuthenticationState" />
which means that if you try to inject MagentoWishlistModelAuthenticationStateInterface
in some of your class, Magento will make sure you get instance of MagentoWishlistModelAuthenticationState
And if for some reason you are not happy with the default class used, you can always tell magento to use another class in you module /etc/di.xml
file.
add a comment |Â
up vote
1
down vote
You should use the interface
MagentoFrameworkObjectManagerInterface
as Magento has mechanism called Dependency injection. This is originally provided by symfony/dependency-injection
package - look it up in your composer.lock file.
In effect the dependency injection mechanism will locate that actual class that implements the given interface. You need not to worry which is the actual class that gets instantiated.
For example, each module will define a preference for a given interface.
Lets take a look at file /vendor/magento/module-wishlist/etc/di.xml
There is a code like
<preference for="MagentoWishlistModelAuthenticationStateInterface" type="MagentoWishlistModelAuthenticationState" />
which means that if you try to inject MagentoWishlistModelAuthenticationStateInterface
in some of your class, Magento will make sure you get instance of MagentoWishlistModelAuthenticationState
And if for some reason you are not happy with the default class used, you can always tell magento to use another class in you module /etc/di.xml
file.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You should use the interface
MagentoFrameworkObjectManagerInterface
as Magento has mechanism called Dependency injection. This is originally provided by symfony/dependency-injection
package - look it up in your composer.lock file.
In effect the dependency injection mechanism will locate that actual class that implements the given interface. You need not to worry which is the actual class that gets instantiated.
For example, each module will define a preference for a given interface.
Lets take a look at file /vendor/magento/module-wishlist/etc/di.xml
There is a code like
<preference for="MagentoWishlistModelAuthenticationStateInterface" type="MagentoWishlistModelAuthenticationState" />
which means that if you try to inject MagentoWishlistModelAuthenticationStateInterface
in some of your class, Magento will make sure you get instance of MagentoWishlistModelAuthenticationState
And if for some reason you are not happy with the default class used, you can always tell magento to use another class in you module /etc/di.xml
file.
You should use the interface
MagentoFrameworkObjectManagerInterface
as Magento has mechanism called Dependency injection. This is originally provided by symfony/dependency-injection
package - look it up in your composer.lock file.
In effect the dependency injection mechanism will locate that actual class that implements the given interface. You need not to worry which is the actual class that gets instantiated.
For example, each module will define a preference for a given interface.
Lets take a look at file /vendor/magento/module-wishlist/etc/di.xml
There is a code like
<preference for="MagentoWishlistModelAuthenticationStateInterface" type="MagentoWishlistModelAuthenticationState" />
which means that if you try to inject MagentoWishlistModelAuthenticationStateInterface
in some of your class, Magento will make sure you get instance of MagentoWishlistModelAuthenticationState
And if for some reason you are not happy with the default class used, you can always tell magento to use another class in you module /etc/di.xml
file.
answered Sep 4 at 10:56
Marjan
7118
7118
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240008%2fwhat-is-difference-on-both-object-manager%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password