In inherited application there is strongly used hibernate. Entities model looks like it tries to build a full domain model - they have states and behaviours. However all functionalities use entities in view (and Session on view pattern) and it is difficult to do hermetic model especially then all entity attributes has public setters and getters.
My idea were:
- to retrieves entities only to service level and then map them to immutable dto and dto use in views or if it was necessary map them to mutable Java Plain Object.
- change access type for data in entitles. Till now there was property access an there was impossible to remove setter method from entity. I prefer field access. It is much more transparent and allow to remove getters and setters which can be implemented by Lombok library.
- add new layer - application layer which collect a few independent functionalities and share them to controller.
- I changed packaging of my classes. Classes were included to packages split in order: layer name, functionality. Now I package my classes in order: functionality, layer, but I still thinking about removing layer part of packages and much more granulate functionality.
- reports contains data from many independent tables. I get data by native sql directly mapped to immutable dto.
Now I was focused on bounded domain model and how to resolve it in my application. In this application I should much more use CQRS pattern.
Anyway I think about some other implementation problems, ex. how should I implement JPA entities of bounded context? One context needs only a few attributes of all model, other needs some other but that attributes are archived in one db table.
I still looking for best solutions:)
Bellow I added a few interesting resources:
ddd series
ddd-in-practice
dddexample
domain-driven-design-with-java-ee-6
ddd-and-spring