answersLogoWhite

0


Best Answer

Such a pattern involves at least three elements: adependent, its dependencies and an injector(sometimes referred to as a provider or container). The dependent is a consumer that needs to accomplish a task in a computer program. In order to do so, it needs the help of various services (the dependencies) that execute certain sub-tasks. The provider is the component that is able to compose the dependent and its dependencies so that they are ready to be used, while also managing these objects' life-cycles. This injector may be implemented, for example, as a service locator, an abstract factory, a factory method or a more complex abstraction such as a framework.

The following is an example. A car (the consumer) depends upon an engine (the dependency) in order to move. The car's engine is made by an automaker (the dependency provider). The car does not know how to install an engine into itself, but it needs an engine in order to move. The automaker installs an engine into the car and the car utilizes the engine to move.

When the concept of dependency injection is used, it decouples high-level modules from low-level services. The result is called the dependency inversion principle. public interfaceEngine { public float getEngineRPM(); publicvoid setFuelConsumptionRate(floatflowInGallonsPerMinute); } public interface Car { public float getSpeedInMPH(); publicvoid setPedalPressure(float pedalPressureInPounds); }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is dependency injection and how is it implemented in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Who firstly implemented Java compiler in Java?

James A. Gosling for Sun Microsystems implemented it on a PDA device named Star before it was named Java. As for who implemented it under the Java name first is near impossible to determine.


How does a dependency injection work?

Dependency injection is a phrase that is relevant to computer science. It is a software design pattern that allows code to be changed at run-time or compile-time.


What are the feature of java which have been implemented in c?

None, as C was made prior to Java.


How is dependency injection used?

Dependency injection is the linkage of one thing to another and the ability to switch between injections. Often this is used in computer applications such as a network being dependent on one particular number of computers. thus when one breaks off from this network the dependency is broken.


What java interface must be implemented by all threads?

Runnable interface


Why a function is not defined in to another function?

A function is not deigned in to another function. It is because that would lead to dependency injection.


What year java was implemented?

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform.Newer versions of Java have been released on a regular basis...


What do you understand by Dependency Injection in AngularJS?

Dependency Injection (DI) is a design pattern used in AngularJS that helps to manage dependencies between different parts of a web application. In DI, components are designed to depend on abstractions rather than concrete implementations. This allows for greater flexibility and easier testing of components in isolation. AngularJS provides a built-in dependency injection system that allows developers to inject dependencies into components such as controllers, services, and directives. Dependencies can be injected using constructor injection or property injection, and can be provided by other components or by the AngularJS framework itself. DI is a key feature of AngularJS and is essential for building modular, reusable, and testable code. jai Infoway Provide Service


What is meant by native method in java?

The Java native method is a great way to gain and merge the power of C or C++ programming into Java. To use Java as a scientific and high performance language, when efficient native Java compilers are not fully implemented, use native method can boost the performance to at least the speed of C compiled code.


How is Java persistence done?

Java persistence is implemented using serialization. Serialization is a technique in java using which the contents of a java object (A class instance) can be written into a flat file. This value can be unserialized or deserialized at a later point of time to create the object. Any class that implements the Serializable interface can be serialized.


Why java is not purely object oriented programming language?

Java IS a pure OOP language. All types, including the built-in types, are implemented as objects.


Are there any Air Java adapters that has already been implemented?

Merapi is a bridge between AIR and Java. It is currently in alpha-testing and they are looking for AIR developers to help beta test their bridge.http://www.merapiproject.net/