I have the following design of my classes:
public interface Device {
void create();
}
public class Printer implements Device {
@Override
public void create() {
}
public class Mouse implements Device {
@Override
public void create() {
}
public class ProcessImpl implements Processor {
private final Map<String, Set<String>> deviceMap = new HashMap<>();
@Override
public void process(String input) {
populateMap(input);
//call to `provision(deviceMap)`
}
deviceMap
values are arranged like this for example: {123=[P, M], 224=[C, P, M]}
where 123
is an ID
and String values C',
P,
M` represents devices to be created against the corresponding ID.
My question is, how can I iterate over this map in provision(deviceMap)
method and create
the devices by calling their corresponding create()
method. (achieving polymorphism) e.g.
When P
-> Call create()
in Printer
implementation of Device
. What is good design/pattern I can use to structure the classes? Can enum
help with this or is there a better cleaner approach ?
Aucun commentaire:
Enregistrer un commentaire