I read somewhere that one should be generous in creating value objects for entity properties that are part of the class API.
So I did that with my project entity/aggregate, but it still looks weird:
return new Project(
new ProjectId( $project->post->ID ),
new DestinationNumber( $DestinationNumber ),
new AssociatedClient( $associatedClientId ),
new NotificationForm( $NotificationFormName ),
new Status( $project->post->ID, $StatusFieldsAndValues ),
new Settings( $project->post->ID, $SettingsFieldsAndValues )
);
All these entity properties have getters (like getStatus), which means they are relevant for other services or repositories. So, should I make the effort to create a value object in any case, or is there a line somewhere? My example seems like overkill.
new
keywords in the same place is not exactly unprecedented; the problem here is that you need to have a good understanding of why.$project->post->ID
be an instance ofProjectId
instead of a primitive, then you have one less thing to new here.