about ddd domain model and cqrs

63 views
Skip to first unread message

闫军华

unread,
May 25, 2016, 2:20:15 AM5/25/16
to Axon Framework Users
hi,all

context:

 I have a project about Product Management System. The operator can add new product with it .


question:

As a product , some info (property) is optional and some is mandatory.  How to design command object for product creation, if contain the optional info ? 

In my opinion,  the create command should only contain mandatory info ,and the optional info can be updated after creation.

any suggestion?



sample code (may be):

class CreateProductCommand
{
  private String name;  //mandatory
  private String catId;  //mandatory

 public CreateProductCommand(String name,String catId)
{
  this.name=name;
 this.catId=catId;
}

some get method...

}



class Product
{
  private String uuid;   //mandatory
  private String name;  //mandatory
  private String catId;  //mandatory
  private String description;  //optional

public Product(String uuid,String name,String catId)
{
  apply(new ProductCreatedEvent(...));
}

}

René de Waele

unread,
May 25, 2016, 12:58:47 PM5/25/16
to axonfr...@googlegroups.com
Hi,

In my experience/opinion it is best to issue a single create command containing both mandatory and optional data. 

A common use case is user registration. Here, the command to create the user usually contains the user id and user profile. This user profile might be rudimentary with little useful data if the signup process is basic but the advantage is that a subsequent command to edit the user profile also contains a user profile object. This way, both commands share the same language which usually makes life easier. 

In general, it should be clear what the intent of a command is. By splitting up your command it is harder for your aggregate to know what's going when it needs to handle the second command. 

Best,
Rene 
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

闫军华

unread,
May 25, 2016, 10:55:53 PM5/25/16
to Axon Framework Users
 thanks René de Waele

if the command contains all datas, handler will use ALL data to create new ENTITY(product,above sample), and entity should have a constructor with ALL parameters.

according to the business, some optional data can be ignored when entity created, so that confuses me.


should I add a constructor of entity class with ALL OPTIONAL parameters?    

René de Waele

unread,
May 26, 2016, 12:50:26 AM5/26/16
to axonfr...@googlegroups.com
Just shooting from the hip here, but couldn't you have a constructor as follows:

public ProductEntity(String productId, ProductData productData) {
this.productId = productId;
setProductData(productData);
}

The setProductData method can also be called when the product data is updated at a later time. 

You can annotate ProductData with @Embeddable to prevent copying over all it's fields to the ProductEntity. 

Rene
Message has been deleted

闫军华

unread,
May 26, 2016, 2:07:12 AM5/26/16
to Axon Framework Users

got it

thanks again


Joshua Yan
Reply all
Reply to author
Forward
0 new messages