Ist das irgendein Design Muster?

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

Factory dürfte das erste Wort sein, was hier dringend fehlt,
allgemein mächtiges Werkzeug, welches gerne auch Singletons ordentlich auf die Nase haut,

hat auch was von Registry, hier ein Link in dem man auch Klassen in der Factory registrieren kann, allerdings mit String-Key
http://www.oodesign.com/factory-pattern.html

dass man Implementierungsklassen zu Interfacen ablegen soll ist gar nicht schwer zu raten, aber steht ja auch schon im Code

die primitiveMap klingt nach etwas für primitive Datentypen, da gibt es auch durchaus Besonderheiten

{
    public static void main(String[] args) throws Exception
    {
        Class a = int.class;
        Class b = Integer.class;
        Class c = Integer.TYPE;
        System.out.println((a == b) + ", " + a.isPrimitive() + ", " + b.isPrimitive());
        System.out.println(a == c);

        Method m = Test2.class.getDeclaredMethods()[1];
        Class d = m.getParameterTypes()[0];
        System.out.println((a == d) + ", " + d);
        System.out.println(m.invoke(null, new Integer(2)));
    }

    static String x(int k)
    {
        return "geht";
    }
}

allerdings dürfte die normale Map dazu reichen, ich sehe keinen Sinn und Unterscheidung ist kaum in zwei Zeilen zu machen

und verwende doch JAVA-Tags statt CODE-Tags