Dependency injection: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit
Assembly: Minor improvements
Tags: Mobile edit Mobile web edit
Line 184:
public class Program {
 
public static void main(final String[] args) {
// Build the service.
final Service service = new ExampleService();
 
// Inject the service into the client.
final Client client = new Client(service);
 
// Use the objects.
Line 212:
public class Injector {
 
public static void main(final String[] args) {
// Details about which concrete service to use are stored in configuration separate from the program itself.
final BeanFactory beanfactory = new ClassPathXmlApplicationContext("Beans.xml");
final Client client = (Client) beanfactory.getBean("client");
System.out.println(client.greet());
}