0
votes

I write in java and try using DDD.

  1. I have domain model with interface for repository, repository has interface where is implemented in infrastructure layer (IoC).
  2. I would like that only aggregation roots class and interfaces had package scope public. Entity, domain service, VO should had package scope private.

App schema (Interfaces is controllers, GUI etc.)

My question is:

  • How save data to database from aggregation root without getters. I would like have only clean buissnes behavior. Maybe my aggregation root should create DTO object?(but is smell)
  • Factory should be in domain package, application or should have interface in domain package?
1
See my answer it boils down to the sameTseng

1 Answers

1
votes

How save data to database from aggregation root without getters. I would like have only >clean buissnes behavior. Maybe my aggregation root should create DTO object?(but is smell)

May be you are looking for ports-and-adapters architecture pattern.

Usual approach - place business and infrastratucture code in same package but in different modules

You even can make your AR non-public without public getters/setters.

Example:

https://github.com/ddd-by-examples/factory

look at

Examples of Domain Model in code: aggregate ProductDemand entity DailyDemand

in description - ProductDemand and DailyDemand not public, placed in demand-forecasting-model module at package io.dddbyexamples.factory.demand.forecasting

Now look at package io.dddbyexamples.factory.demand.forecasting in module demand-forecasting-adapters and you will see infrastructure implemmentation