Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

domain driven design - DDD modelling settings as Value Objects

I am attempting to build an application in a DDD way. Imagine the Aggregate root is a 'Page' which has other aggregates such as Author, Commenter, Comments, Status etc...

A page can also have various settings such as:

  • Private page
  • Allow comments
  • Allow anonymous comments
  • Lock after x Date
  • Slug

I am trying to consider the best way to model these 'settings'. Currently I am looking to have a Settings collection that has each individual setting as a value object. As you can see some of these are essentially boolean values and others might contain specific values such as a date. Given there might be dozens of settings, some with defaults, do I model the 'settings' collection with each specific setting, or just as a collection with the applicable settings?

Is there a 'better' or standard DDD way to approach this problem? I was considering using the specification pattern here but have concluded it doesn't really apply

Sorry a cheeky second question....

A page can have one of many statuses (e.g. draft, published, scheduled, archived) but only one status at a given time. Similar question in terms of the best way to model this. As a status represents something that has an identity I have implemented the status as an entity for the moment. I was wondering would a better approach be to model this as a workflow or a status history even?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First let me say that the aggregate you are planning to create could be too big, double check that since creating an aggregate implies some trade offs like that you can only access the child entities from the aggregate root, and that all changes in the aggregate are atomic. To avoid having a too big aggregate you could have AuthorId as a VO inside Page instead of the full Author entity.

About the settings thing, as far I know DDD doesn’t have some directives to design this. But I’d try to have Settings collection of some interface, the I’d have an implementation for each setting type: Boolean, date...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...