I am struggling with construction of ValueObjects during life cycle of a command.
Here is my situation:
My question is where I should put Object Creation logic. or in other words which component of DDD is responsible for initialisation of Objects (Value Objects, Entities etc.) for Aggregates to work with?
My question is where I should put Object Creation logic. or in other words which component of DDD is responsible for initialisation of Objects (Value Objects, Entities etc.) for Aggregates to work with?
The usual answer is that domain object creation happens via "factories" (see Evans, chapter 6), that are usually exported from the domain model and invoked by the application code that needs them.
A factory might be an object in its own right, or it just be a function, or even a constructor.
A review of the DDDSample by Citerus might help illustrate:
Here, the controller extracts the necessary data (as primitives) and passes that information toward the changeDestination
logic.
At the next class in, the Strings are replaced with Value Objects
; the TrackingId constructor and the UnLocode constructor implement the factory role in this case. The value objects are then passed toward the changeDestination
logic.