service locator pattern

This commit is contained in:
mherbaghinyan 2018-04-20 21:38:28 +04:00
parent 78a6c223eb
commit 81b9a8971e
2 changed files with 8 additions and 1 deletions

View File

@ -6,7 +6,13 @@ package com.baeldung.designpatterns.service.locator;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
MessagingService service = ServiceLocator.getService("EmailService"); MessagingService service = ServiceLocator.getService("EmailService");
service.getMessageBody(); String email = service.getMessageBody();
System.out.println(email);
service = ServiceLocator.getService("SMSService");
String sms = service.getMessageBody();
System.out.println(sms);
} }
} }

View File

@ -4,6 +4,7 @@ package com.baeldung.designpatterns.service.locator;
* Created by Gebruiker on 4/20/2018. * Created by Gebruiker on 4/20/2018.
*/ */
public class ServiceLocator { public class ServiceLocator {
private static Cache cache; private static Cache cache;
static { static {