This might look like a beaten question, but could not find an answer at SO.
I am developing a simple Order Processing application. Quite bit a domain logic so i chose the domain model pattern. Every Order has a “OrderType” called “Ordinary” or “Express”.
I have a Order entity and I exposed a int property called OrderTypeID as I thought I could store the OrderType’s Id in that int field. Worked fine, but when I had to retrieve the order, I could populate back the integer “Order Type” Id, but I need to show the “OrderType – Express or Ordinary” in the screen. So Order entity when it goes down to persistence goes with Id but when it comes back it should become a text !!!!
How do I do this with respect to modelling the Order entity object, should I store the Ordertype as a whole entity (may be a OrderType class0, if yes, how will the repository for the “Order” class split the Ordertype so that i only persist the Id?
any points would be appreciated
Cheers
VJ
A few suggestions/observations.
OrderTypesounds like a Value Type, not an Entity. Perhaps you could implement as an enum? Something likeDepending on your language you may be able to extend the enum to return a more friendly expression (e.g. by overriding
toString()in java). More details on java enums here.Even if you can’t/choose not to use an enum the principle is the same: implement
toString()to return a meaningful value. In both cases it makes the human-readable value intrinsic to the OrderType class. You should also make instances immutable (implicit with an enum).Assuming
Orderis your aggregate root, you’d expose an interface that accepts/returns an instance ofOrderType– not an integer. For example:hth.