1

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?

rocksNwaves
  • 5,331
  • 4
  • 38
  • 77

1 Answers1

2

Simply this is a dependency from SomeClass towards Type.

See Difference between association and dependency?

qwerty_so
  • 35,448
  • 8
  • 62
  • 86