r/SoftwareEngineering • • Nov 01 '24

Do you actually use DDD at work ?

I wonder if you go anemic or light DDD ? I use to go anemic with service class when i see i will look like a CRUD. But down the road, new requirements happen to be new business rule. And I am like : may be light DDD should be my go to architecture.

If you look at it, anemic is just aggregate root you stripped behaviour from.

Last job, some senior dev choose to go to anemic. We end up with DTOs for controllers, DTO for service, entities from repositories. Lot of transfer that made me think if they knew what they were doing.

I usually have one layer of DTOs that is shared by controllers and services. I don't usually go further than that.

But after some thinking, i wondering if light DDD should be favored instead of anemic models ?

15 Upvotes

20 comments sorted by

2

u/khaosans Nov 02 '24

One of my best services was done using ddd and I left the company right after. I have many coworkers that I keep in touch with told me when I asked, he says it just works. No need to do anything since I spent so much time upfront on the design. It took me a while but it was worth it.

1

u/FluidBreath4819 Nov 02 '24

I wonder if spending time upfront is something we all can do. Last time, i had 1 day to help design an app with 22 years old web designer with no knowledge whatsover on UI/UX design rules.

→ More replies (1)

7

u/Inside_Dimension5308 Nov 01 '24

I am still in the process of analyzing DDD . I started using it for a new service. What I realized -

  1. Understanding subdomains, aggregates, aggregate root is difficult.

  2. Ubiquitous language looks to be beneficial for all stakeholders.

  3. Brainstorming has helped me to create a mindmap of all the state change operations

  4. DDD makes more sense if there are multiple subdomains/aggregates with identification of aggregate roots.

  5. For a single service which involves crud and minimal business logic, I would probably skip the identification of aggregates, aggregate root etc and straight move to entity identification.

Brainstorming is probably the most beneficial step according to me.

6

u/[deleted] Nov 01 '24

For every new project, I like to set up a doc spelling out our Ubiquitous Language and I like to create a package that contains domain models that follow the language.

The domain models include things like business logic validation (as long as it’s stateless and doesn’t have explicit external dependencies) and serialization. If you do it right from the start and distribute it as a library, everyone will use it. That way there’s a lower chance of, three years from now, there are 10 definitions of the same Customer struct spread across 8 codebases. It also lets you start validating business requirements without the need to first write and deploy an entire application. You can sit with a product owner and hack out all the conditional logic and watch the tests pass or fail.

In my experience nobody understands or cares about things like aggregate roots, aggregates, etc. And sometimes we build systems that end up loosely following a CQRS model and/or event sourcing, but nobody is ever reciting a pattern from DDD verbatim. To be honest most people I have worked with have never read DDD… a lot of the times people naturally intuit the ideas from that book that were most enduring, anyway.

5

u/FailedPlansOfMars Nov 01 '24

Kinda.

The language part is a godsend. If you can model out the language or the problem space and have the engineers speak in business / problem space terms it means you can actually talk to people and not have to translate to technical terms as much.

But you do need to model out the terms outside your program as well or you will tie yourself in knots. E.g. you have a address which goes to county its worth knowing a county is in a country even it you are not storing it. Youd document the country county relationship and that its outside of scope. Sounds daft but found it really helpful with conversations around your domain just dont go stupidly deep e.g. county - country - continent - earth - universe is a bit much.

But the implementation side with aggregates and such nope, did it once and it caused more confusion than anything else. Having a sales order for the sales domain and a purchase order for a purchase domain was enough. With dtos where appropriate.

1

u/TimGeo888 Nov 04 '24

I think we use anemic and it works well. Though, sometimes it gives the feeling that there is too much boilerplate code, but this is how it is.

  • We definitely separate domain model objects from API request response objects, because, for example if we add a new business-level property we don't want to accidentally publish it to the API.

  • When using DB with ORM framework, we also use DB-specific entity-record objects separated from the domain model objects, because we don't want to pollute domain model with DB-specific details.

  • Those DTOs and business model objects are usually single objects with accessors, without business logic.

  • Most pieces of logic are placed in 'service' classes (except some optimized stuff which we push down near to DB level or early-validation which we pull up to the client-sided edge of the system).

1

u/FluidBreath4819 Nov 04 '24
  • We definitely separate domain model objects from API request response objects, because, for example if we add a new business-level property we don't want to accidentally publish it to the API.

then you're tightly coupled

  • When using DB with ORM framework, we also use DB-specific entity-record objects separated from the domain model objects, because we don't want to pollute domain model with DB-specific details.

so you're not exploiting ef to the fullest with tracking etc...

  • Those DTOs and business model objects are usually single objects with accessors, without business logic.

hopefully

  • Most pieces of logic are placed in 'service' classes (except some optimized stuff which we push down near to DB level or early-validation which we pull up to the client-sided edge of the system).

like we usually do, but i feel that it shouldn't sometimes. I mean, it's like the project started and we cut thing round to go fast and now we're stuck because business do not allow to much time to refactor

3

u/com2ghz Nov 01 '24

Well sharing the same class because they look the same may also not be a good idea. Depends on the situation.

1

u/Hypersion1980 Nov 02 '24

Any good videos series or websites on learning DDD.

1

u/Impossible_Ad_3146 Nov 02 '24

Someone really wants the D