This is a useful Library to manage Service Object.
What is Service Object? Service Object is a class which is serviced to client class. Usually Service Object is the Singleton (but not always). The Client class doesn't need to know about it's concrete Class name, Instantiation, destruction, just lookup the Servce object and call the public method of this. This idea is similar CBD idea.
To solve this problem, It need some managing class. ServiceManager is this.
This project is inspired by Avalon, HiveMind and etc... Some code was borrowed from Avalon.
In developping the application. This is designed to solve the following problems.
Sometimes, It need some Singleton-Class. for example Logger, Configuration, Global Informagion,... etc. Of course, Making the Singleton-Class is easy, But it's tedious work. Furthermore, If a class which will be a Singleton-class is a already existing class(3rd-party library, ...) and It can't be modifid. Then, It must create a new class which is maintain that class with single-instance.
Singleton mean only one instance exist. but sometimes It need multi instance. For example, there are client classes. some classes use singleton A, and the other clients use singleton B. If A and B is same class. It's not possible.
Example code
Before
SomeService a= SomeServie.getInstance(); SomeService b= SomeServie.getInstance(); a.saveData("for A"); b.saveData("for B"); // It is invalid. because a == b ( same insatnce)
After
SomeService a= (SomeService)ServiceManager.lookupService("serviceA"); SomeService b= (SomeService)ServiceManager.lookupService("serviceB"); a.saveData("for A"); b.saveData("for B"); // It work. Because a != b
For example, There are one Interface IndexWriter, and It's sub-calss MemoryIndexWriter, FileIndexWriter, JDBCIndexWriter.
Source will be like that.
IndexWriter writer=null; // Not Good, becauser It can't change a Concrete Class unless source code is changed. writer= new MemoryIndexWriter(); // Good, because It can easily change a Concrete Class. of course It can be changed with AnotherIndexWriter. writer= (IndexWriter)ServiceManager.lookupService("writer"); writer.makeIndex(doc); // do it's job