ahoi's avatar
Level 5

DDD: Where to store "shared classes"

I am currently checking out the DDD pattern and (tried) to refactor a project of mine accordingly.

Now I got a case where I don't really know what to do: Some business logic can be called by multiple entities. In my case it's possible to mark items as hidden.

The item can be a Product or a Category (or many more).

The related event is called MarkedItemAsHidden, fired by an action handler called MarkItemAsHidden, which accepts the item as first parameter and fires the event based on the item's class.

So I got:

  • Events: MarkedItemAsHidden
  • Actions: MarkItemAsHidden($item)
  • Projector: HidingProjector

But where do I put those classes?

My app has a Domain-directory, which includes:

  • Product
  • Category
  • Cart
  • ...

but I can't really decide where to put these "shared classes".

0 likes
3 replies
ahoi's avatar
Level 5

Thank you, this is very helpful!

martinbean's avatar

@ahoi DDD isn’t an architectural pattern. It’s not storing your files in a particular way. It’s building software that accurately models and business and its processes by speaking to subject matter experts. Not carving your codebase up into arbitrary “modules” that you then call “domains”.

Please or to participate in this conversation.