🧰 Developer’s toolbox: 💉 Dependency Injection Design Pattern

Vee Lesyk
Dots and Spaces
Published in
1 min readSep 5, 2019

Instead of creating the dependency internally an object can receive it from the outside.

Wikipedia says:

In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A “dependency” is an object that can be used, for example as a service. Instead of a client specifying which service it will use, something tells the client what service to use. The “injection” refers to the passing of a dependency (a service) into the object (a client) that would use it. The service is made part of the client’s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.

The intent behind dependency injection is to achieve Separation of Concerns of construction and use of objects. This can increase readability and code reuse.

Github repo: link.

Example

Consider the case of of creation of a car with different engines.

Swift

DependencyInjection.js

TypeScript

DependencyInjection.ts

Output

DependencyInjection Output
Dependency Injection.

P.S. We would be happy to see comments according to mistakes & typos.

--

--

Vee Lesyk
Dots and Spaces

#h+ #livemoredomore Adventurer. Unique experience wizard. Maker of things. Convergence commander. Information warlock. Problem solver. System: ☉; Planet: ♁.