My aggregate root is "Post" and sub aggregate is "Comment". In my database I have a table called "ForbiddenWords" with one column "Name" (it contains words for example: "sex", "porn"). If someone wants to add a comment, he can't use forbidden words. I need to create a class "ForbiddenWords" to validate a comment. Is this class a Value Object?


1 Answer 1


A value object is an object without identity. According to your description, a forbidden word is a value object.

For example, you would not be able to distinguish in your table two rows with the same word. Moreover if you would change a word, it would be different word with no relation to the previous one (the identity would not persist after across the changes).

  • OK, thank you, so you resolved my doubts. :) One more question - do you think I can check if a comment doesn't contain forbidden words in a command handler CreateCommentCommandHandler, or it has to be in the domain model Comment? Feb 16, 2022 at 7:57
  • Command handlers should not contain business logic. Checking comments for forbidden words is business logic.
    – Rik D
    Feb 16, 2022 at 8:37
  • 1
    Where to put validation logic is a broad topic. There are a couple of questions here (for example softwareengineering.stackexchange.com/q/210799/209774 or softwareengineering.stackexchange.com/q/341564/209774 ). If you don’t find a suitable answer, I’d suggest that you raise a separate question (and explain what makes you hesitate about not having it in the domain model).
    – Christophe
    Feb 16, 2022 at 8:38
  • thank you Christophe :) Feb 16, 2022 at 8:43

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