java/j2ee tips and blueprints
java/j2ee tips and blueprints
It is a very sad thing that nowadays
there is so little useless information.
Oscar Wilde
Java7 Wish: Object/Bean Factory
One of the most critic point for java
return Class.forName(className).newInstance();
Upon since it seems this method bring the ultimate extensibility power to java.
But Now server & client applications became more and more complicated this feature became insufficient.
Today lots of projects try to solve this problem on their own. But one single interface would solve lots of this problems and make it easy to integrate these API’s easily. another point this would bring Factory Pattern info J2SDK
public interface ObjectFactory{
public Object getInstance(objectName);
}
some example implantations:
http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/beans/factory/BeanFactory.html
http://www.opensymphony.com/xwork/api/com/opensymphony/xwork/class-use/ObjectFactory.html
http://hivemind.apache.org/hivemind1/hivemind-lib/apidocs/org/apache/hivemind/lib/BeanFactory.html












I use the following interface which is fairly extensible.
interface Factory<D, E> {
public E acquire(D description);
}
So you could have a Factory<String, Socket> or Factory<Map<String, Object>, DataValue>
final Object o = java.beans.Beans.instantiate(someClassLoader, “fargBarg”);
Or:
final Object o = someJNDIContext.lookup(”fargBarg”);
(Have a look at http://java.sun.com/products/jndi/tutorial/objects/factory/index.html in conjunction with this.)
Or:
final Iterator allInstances = java.util.ServiceLoader.load(someInterface).iterator();