Simplify ComponentLocator

This commit is contained in:
2025-04-27 22:52:25 +02:00
parent ac854ed4f1
commit c38835fd7b
22 changed files with 57 additions and 71 deletions

View File

@ -0,0 +1,29 @@
package fabrik.simulator.pic16f84;
import fabrik.simulator.pic16f84.interfaces.*;
import java.util.HashMap;
public class PICComponentLocator {
// https://en.wikipedia.org/wiki/Service_locator_pattern
private final HashMap<Class<? extends PICComponentInterface>, PICComponentInterface> componentCatalogue;
public PICComponentLocator() {
super();
this.componentCatalogue = new HashMap<>();
}
public void registerComponent (Class<? extends PICComponentInterface> componentClass, PICComponentInterface component) {
this.componentCatalogue.put(componentClass, component);
}
public <T extends PICComponentInterface> T getComponent(Class<T> componentClass) {
T component = (T) this.componentCatalogue.get(componentClass);
return component;
}
public void initAll() {
for (PICComponentInterface component : componentCatalogue.values()) component.initialize(this);
}
}