Talk:Dependency injection

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing / Software (Rated Start-class, Mid-importance)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Mid  This article has been rated as Mid-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Software (marked as Mid-importance).
 

Links[edit]

Framework based DI Code Example[edit]

I highly discourage anybody from using hard coded strings in-line. The example in the last section of the page would be better if we added an static class to it that contains the strings:

//static class provided by the framework or written by the user to indicate which dependencies are available
public static class MyAvailableServices{
    public static final string CarBuilderService = "CarBuilderService";
    public static final string VanBuilderService = "VanBuilderService";
}

public class MyApplication {
    public static void main(String[] args) {
        Service service = (Service)DependencyManager.get(MyAvailableServices.CarBuilderService);
        Car car = (Car)service.getService(Car.class);
        car.setPedalPressure(5);
        float speed = car.getSpeedInMPH();
    }
}

Registry Pattern[edit]

Should not this article reference the Registry Pattern which was very prevalent until IoC/DI was popularised?

References[edit]

UML class and sequence diagram[edit]

I would like to share the following UML diagrams I have published on w3sDesign, an Open Online Learning resource for learning object-oriented software design patterns. Your comments are welcomed!

Dependency Injection UML class and sequence diagram

In the above UML class diagram, the Client class doesn't instantiate the ServiceA1 and ServiceB1 classes directly. Instead, an Injector class creates the objects and injects them into the Client. This greatly simplifies the Client class because it can use objects without having to care about how they are created.
The UML sequence diagram shows the run-time interactions: The Injector object creates the ServiceA1 and ServiceB1 objects. Thereafter, the Injector creates the Client object and injects the ServiceA1 and ServiceB1 objects.

Vanderjoe (talk) 12:31, 9 July 2017 (UTC)