WorkinHard
WorkinHard

Reputation: 1

How to make the best of an Anemic Domain Model given no other choice

So I started my 2nd developer job after spending 10 years at my first company and not really feeling I earned the title of a senior developer. It was java development but we were working with an anemic domain model and the application in my opinion was a huge difficult-to-test mess. Unfortunately the code base that I'm working with now is exactly the same and I recently had another interview where the interviewer described their Hibernate model as being light weight and just containing setters getters as well. So it appears this is quite common across the industry.

There's plenty of articles describing the anemic domain model as an anti-pattern and also some articles where it is described as perfectly fine for simple systems. But I haven't seen any examples of making the best out of working with a large enterprise system with an ADM.

Has anyone had experience with this? Are there any best practices for creating a loosely coupled system that contains unit tests that are readable and actually valuable? I really want to take pride in my work but am losing hope.

Edit: To the developers that advocate business logic being contained in services:

Upvotes: 0

Views: 118

Answers (1)

Alexey Zimarev
Alexey Zimarev

Reputation: 19640

You may consider your persistence model, which you now think about as the anemic domain model, as what it is - the persistence model for your domain model state.

If you do that, you probably can create a real domain model, which will have its state stored inside the persistence model objects (State pattern). Then, you can have your logic inside this new domain model. Reading your comment above, I would say you can convert your "manager/service" classes to state machines, you can call them aggregates if they match with transaction boundaries, and have their state in POJOs persisted by Hibernate as it is done now.

Upvotes: 1

Related Questions