My last post about rich domain objects caused some traffic in the comments area. It seems like the whole idea of rich, persistent domain objects is controversial. Especially the getters/setters are discussed a lot. In my opinion there is no single truth. Rich Domain Objects (e.g. PDOs from p4j5) are suitable in case:
- You need inheritance and polymorphism (e.g. special computation in concrete classes)
- The behavior can be state dependent.
- A method call can change the state of not only one object, but whole object graph (or tree).
- Shortly: when object orientation is needed :-)
The real world is even more complicated. Sometimes neither PDO, nor PAOs can be used, and dataset oriented styles are more appropriate. Especially stored procedures are not directly supported by JPA, so Integration Services (like DAOs, see Integration Service from p4j5) have to be realized to access the stored procedures and map the results.
But also from the business perspective the object-relational mapping is not always the way to go. Especially reports, imports, exports can be often much easier realized with dataset, than oriented persistence.
...we just have to use the right tool for the job
Cloudy Jakarta EE and MicroProfile: Microservices, Clouds and Beyond Jakarta EE / MicroProfile airhacks workshops at MUC airport, Winter Edition
airhacks.fm the podcast:
Stay in touch: airhacks.news.