Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:01:26+00:00 2026-06-01T15:01:26+00:00

I’ve been programming for some time but never got interested in knowing in theory

  • 0

I’ve been programming for some time but never got interested in knowing in theory what each concept means, I may be using a variety of programming concepts, but without knowing it.

Service Locator:
For me, refers to a record of shortcuts to speed up development by reducing the amount of code. One question is: may Locator refer to namespaces/classes only, or I can have a registry of variables?

Here is my understanding of it:

$locator = new ServiceLocator()
$locator->set('app', new System\Application());
$locator->set('db', new System\Pdo());

// Get the objects
$locator->get('db')->connect();
$locator->get('app')->run();

Dependency Injection (and Dependency Injection Container):
Injecting objects within objects, allowing faster access to these regardless of the factory pattern. And DI Container?

Here is my understanding of it:

$app = new System\Application(System\Config::load());

Inversion of Control:
Don’t understand this Design Pattern (or understand but don’t know if what I do is IoC)

Then, in theory (preferably with simple examples), what does each of these concepts mean? Am I correct, or what is wrong / can be improved?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:01:28+00:00Added an answer on June 1, 2026 at 3:01 pm

    I think you understood correctly the Service Locator.

    About Dependency Injection, means that if an object has constructor and/or property dependencies, these are injected in the object by outside, as opposed to the object getting the dependencies by itself

    public class MyClass
    {
       private $_dep;
       public function __construct($dep=null)
       {
           //$dep has to be injected
           $this->_dep=$dep;                           
       }
    
       //this is wrong because it couples MyClass to a specific Dependency implementation
       public function __construct()
       {
           $this->_dep=new Dependency();
        }
    }
       $dep=new Dependency();
       $obj=new MyClass($dep);
    

    Usually the constructor takes an abstraction (an interface) as the param, and outside the class is instantiated a concrete implementation which then is passed on to the constructor when creating a new instance of MyClass.

    A DI Container, handles the dependency injection automatically. You just configure it, so that it knows what concrete classes to be returned when an abstraction is asked. The Container handles object creation, injecting dependencies via constructor and/or properties. Depending on the container (I don’t know an example for php, I’m familiar only with .net DI Containers) you might have to register also the types of objects that can be created by
    it.

    Inversion of Control means that instead of a higher level class depending on a lower level class (dependency) implementation, the control is inversed so the lower level class implementation depends on an abstraction required by the higher level class.

    //abstraction defined for the use of higher level class
    public interface  IRepository {}
    
    // that's the dependency, the lower level class  
    public class XmlRepository implements IRepository {}
    
    //the higher level class
     public class MyClass
     {
         public function __construct(IRepository $repo) {}
      }
    

    IoC and DiC go together as the DI Container offers the IoC feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.