Read More
Read now

Dependency Injection

Save

Dependency Injection is a process where by object define their dependencies that are, the other objects they work with, by the constructor argument, arguments to factory method or property that set on the object instance after it is constructed or returned by the factory class, this process is called DI (Dependency Injection).

Why we use Dependency Injection?

The main idea of DI is to decouple the tight coupling for the dependent objects from each other. so that it is usually testable and modifiable.

The problem occurring when in future we have changed some objects instance from an object then code modifiability is too difficult because of we will change all the instances of that object from the application. For Ex.-

there are two Type services that send messages from the application so if we use without DI such as –

In future, if we want to delete or change the TypeA message to another TypeC message then we manually change all the TypeA object from the Application, so it will the very hard process if complex application.

So, How can solve?

We create MessageService Interface that has send message property and all the Services implement MessageService Interface.  and inject MessageService implementation class dependency from MessageApplication class via the setter method.

 

 

 

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home