What is difference on both Object manager?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
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.







share|improve this question


























    up vote
    2
    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.







    share|improve this question






















      up vote
      2
      down vote

      favorite









      up vote
      2
      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.







      share|improve this question












      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.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 29 at 6:09









      Ansar Husain

      790216




      790216




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          2
          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.






          share|improve this answer





























            up vote
            5
            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






            share|improve this answer





























              up vote
              0
              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.






              share|improve this answer



























                up vote
                0
                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.






                share|improve this answer








                New contributor




                Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.

















                  Your Answer







                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "479"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  convertImagesToLinks: false,
                  noModals: false,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                   

                  draft saved


                  draft discarded


















                  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






























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  2
                  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.






                  share|improve this answer


























                    up vote
                    2
                    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.






                    share|improve this answer
























                      up vote
                      2
                      down vote



                      accepted







                      up vote
                      2
                      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.






                      share|improve this answer














                      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.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 29 at 7:08

























                      answered Aug 29 at 6:33









                      Pankaj Pareek

                      2,19211235




                      2,19211235






















                          up vote
                          5
                          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






                          share|improve this answer


























                            up vote
                            5
                            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






                            share|improve this answer
























                              up vote
                              5
                              down vote










                              up vote
                              5
                              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






                              share|improve this answer














                              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







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 29 at 6:54

























                              answered Aug 29 at 6:35









                              Qaisar Satti

                              24.9k115398




                              24.9k115398




















                                  up vote
                                  0
                                  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.






                                  share|improve this answer
























                                    up vote
                                    0
                                    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.






                                    share|improve this answer






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      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.






                                      share|improve this answer












                                      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.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 29 at 6:34









                                      Avesh Naik

                                      15712




                                      15712




















                                          up vote
                                          0
                                          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.






                                          share|improve this answer








                                          New contributor




                                          Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.





















                                            up vote
                                            0
                                            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.






                                            share|improve this answer








                                            New contributor




                                            Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                            Check out our Code of Conduct.



















                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              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.






                                              share|improve this answer








                                              New contributor




                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              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.







                                              share|improve this answer








                                              New contributor




                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              share|improve this answer



                                              share|improve this answer






                                              New contributor




                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              answered Sep 4 at 10:56









                                              Marjan

                                              1766




                                              1766




                                              New contributor




                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.





                                              New contributor





                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.






                                              Marjan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.



























                                                   

                                                  draft saved


                                                  draft discarded















































                                                   


                                                  draft saved


                                                  draft discarded














                                                  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













































































                                                  Comments

                                                  Popular posts from this blog

                                                  Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                                  Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                                  Confectionery