here i am preparing for the final exam and i want some answer give me a clear explanation of topic - dependency injection in java give me the answer of important points with important words answer should be in points 5 points of 10 words and if there this is an example code and please give me an sample example code of it too
Dependency Injection:
Important Words:
Example Code:
public class Client { private Service service; public Client(Service service) { this.service = service; } public void doSomething() { service.execute(); } } public interface Service { void execute(); } public class DependencyInjectionExample { public static void main(String[] args) { Service service = new ServiceImpl(); Client client = new Client(service); client.doSomething(); } }
I hope this helps! Let me know if you need further assistance.