Hallo
In der letzten Aufgabe haben wir ein Singleton Interface bekommen und mussten es implementieren, ich hatte 0 Ahnung wie. Danach habe ich in einem Buch etwas über Singleton nachgelesen und mir war sofort klar wie es geht.
Diesmal haben wir wieder ein Interface welches wir implementieren müssen. Nur ich habeabsolut keine Ahnung was das sein soll.
public interface ComponentRegistry extends PropertyListenSupport {
/**
* Method to be called by a library upon static initialization to register
* the given class so that instances can be created.
* @param <T> generic placeholder for the interface class
* @param clazz the class containing the interface
* @param impl the class containing the implementation
*/
public <T> void registerClazz(Class<T> clazz, Class<? extends T> impl);
/**
* Method to be called by a library upon exit to unregister so that
* no more instances can be created.
* the given class so that Instances can be created.
* @param <T> generic placeholder for the interface class
* @param clazz the class containing the interface
*/
public <T> void unregisterClazz(Class<T> clazz);
/**
* Method to create an implementation of the class given as parameter.
* @param <T> generic placeholder for the interface class
* @param clazz the class containing the interface
* @param args the arguments of the constructor
* @return an instance of the class or null, if the object could not be created
*/
public <T> T retrieveInstance(Class<T> clazz, Object ... args);
}
Ich verstehe nicht was verlangt ist was genau die Methoden tun sollen.
Hier ist die Klasse die das Interface implemtiert, ich poste nur Methoden die ich noch nicht fertig hab. Die Anderen waren einfach und nicht relevant.
public final class ComponentRegistryImpl implements ComponentRegistry, PropertyListenSupport
private static final Logger LOGGER = null;
private static volatile ComponentRegistryImpl instance;
private final transient Map<Class, Class> map;
private static transient Map<Class, Class> primitiveMap;
private final transient PropertyChangeSupport propertyChange;
private ComponentRegistryImpl() {
// Roughly 11 lines of implementation
throw new UnsupportedOperationException("Not yet implemented");
}
public <T>T retrieveInstance(Class<T> needed, Object ... args) {
// Roughly 30 lines of implementation
throw new UnsupportedOperationException("Not yet implemented");
}
public <T>void registerClazz(Class<T> clazz, Class<? extends T> impl) {
// Roughly 2 lines of implementation
throw new UnsupportedOperationException("Not yet implemented");
}
public static ComponentRegistry getComponentInstance() {
// Roughly 1 lines of implementation
throw new UnsupportedOperationException("Not yet implemented");
}
public <T>void unregisterClazz(Class<T> clazz) {
// Roughly 2 lines of implementation
}
Ich will hier keine Lösungen. Sondern nur erklärt bekommen was das Ganze ist. Stichwort was ich in google einegeben kann um rauszufinden welchen Zweck diese Konstruktion hat.
Vorallem verstehe ich nicht wie etwas registriert werden soll und wozu. Da es nur 2 Zeilen sein sollen, denke ich mal es ist was banales.
Dann noch das hier
private final transient Map<Class, Class> map;
private static transient Map<Class, Class> primitiveMap;
Was meint ihr ist der Unterschied? Was ist der Zweck der map und was der von promitivMap
Ist das richtig ?
public <T>void registerClazz(Class<T> clazz, Class<? extends T> impl) {
// Roughly 2 lines of implementation
map.put(clazz, impl);
primitiveMap.put(clazz, impl);
}
liebeGrüße
Zicky