jeudi 17 juin 2021

DDD Modeling - Generic and Specific

Suppose I am buying coffee. There are several types of coffee (A1, A2, A3), but sometimes I want to make a reference to all types of coffee (like if I had a coffee "grouped"). Considering DDD concepts, coffee A1 is different from all types of coffee, so that's their identities and I need to reference both specific and generic Coffee Entity.

I thought I could map it like:

class Coffee{ 
  private CoffeeId id;
  @NotNull
  private Code code;
  private SubGroup subGroup; 
}

Imagine I have an entity PriceTable and sometimes I need to have values to all types of coffee and sometimes by some specific types. For coffee A1, its id would be "ca1", for coffee A2 its id would be "ca2" and for generic coffee could be "cag" and subGroup attribute would be null.

Someone finds another way to transform these use cases into entities? I thought about a Strategy pattern but could not get the code to this

Aucun commentaire:

Enregistrer un commentaire