I'm designing a package where one particular class will accept several enums as arguments to the constructor. Those enums will not become attributes, but they will be used to instantiate objects that are. I don't have code yet, but here is a bit of psuedocode to illustrate my design idea:
Enum Type {
TYPE_A(A::new), TYPE_B(B::new);
private Supplier supplier;
private Type(Supplier<X> supplier) {
this.supplier = supplier;
}
public X createInstance() {
return supplier.get();
}
}
Class SomeClass {
Object someObject;
public SomeClass(Type t) {
someObject = t.createInstance();
}
}
The above idea was inspired by the answer to this question.
How would I classify this relationship between Type
and SomeClass
above?
Aucun commentaire:
Enregistrer un commentaire