0

I'm learning DDD so apologies if the question is too naive. Assume an application that manages user publications developed following DDD and using a RestAPI for external interaction (for whatever front-end layer for instance).

Looking at the Publication model we would have behaviors like ApplyLike, RemoveLike, Comment and so on.

Now assume we are asked to implement the (not yet implemented nor designed) functionality of updating an existing publication through a http-put request from our RestAPI. The author of a publication should be able to modify most of its fields (like title, body text, attachments, etc).

How should I design this behavior of updating an existing publication inside the Publication model?

The solutions I can think of seems clearly wrong to me, which are A: create an Update method with all just set all the updatable fields of the model (which will end up with a huge parameter list and will just expose a meaningless public unique setter accessor for almost all the model fields) B: accept the defeat from option A and just expose public setters for the model fields so the user can modify as they want, and finally C: violate layer separations and just assume that update DTO as part of our domain and create an Update(PublicationDTO) method (which is wrong because our premise is just not right - this DTO doesn't belong to the domain).

I think this is probably more a OO question than a DDD question, but how should I tackle that problem? Maybe I should have different separate behaviors like ChangeTitle, ChangeBodyText?

1
  • You're describing an implementation detail; I'm pretty sure DDD has nothing to say about this. See the answer posted below. Commented Aug 1, 2021 at 16:53

1 Answer 1

1

You are struggling with this question because you are fitting a CRUD problem into DDD.

What is missing in your thought process is ubiquitous language - the terms used and the functionality expressed in the business langauge.

You are not using the language that business people would use. They would never use terms like ApplyLike or RemoveLike- they would probably be named Like andUnlike.

Thinking in the same lines, there is almost always a reason and/or a process with changing something in the publication when the domain is sufficiently complex. When the user changes title, should you notify others who have already consumed the publication? When the body text changes, do you need to index it again for search? When new attachments are added, do you need to post-process the files and convert them to another format, like say PDF? The behaviours will reflect this - UpdateContent, AttachReferenceDocument, Publish, etc.

As you see, when your domain is sufficiently complex, these behaviours will drive the naming and structure of the application. You would seldom have anything named simply Update.

For the example question with publishing, you should probably start with CRUD design and enrich the domain to DDD/CQRS patterns only if and when necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.