Created
August 20, 2019 15:05
-
-
Save amitkma/1c03994127cac64680b29a0e1c58e0c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ServiceLocator... | |
private static ServiceLocator sInstance; | |
public static void load(ServiceLocator arg) { | |
sInstance = arg; | |
} | |
private Map services = new HashMap(); | |
public static Object getService(String key){ | |
return sInstance.services.get(key); | |
} | |
public void loadService (String key, Object service) { | |
services.put(key, service); | |
} | |
..... | |
..... | |
} | |
// A simple assembler class. | |
class Tester { | |
private void configure() { | |
ServiceLocator locator = new ServiceLocator(); | |
locator.loadService("LocalBookFinder", new LocalBookFinder()); | |
locator.loadService("RemoteBookFinder", new RemoteBookFinder()); | |
ServiceLocator.load(locator); | |
} | |
} | |
class Library... | |
BookFinder finder = (BookFinder) ServiceLocator.getService("LocalBookFinder"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment