Hello Software engineers,

So I'm a programmer. Not an "engineer". When I do OOP, I mostly create classes and interfaces the way I want. I do not follow any design patterns... BUT now, not only I want to get better but also I need to write a software that won't be maintained by me...

I read in this book a method to organize classes. They say, for your data, you divide the application into the following layers : Domain (or Model) ; Persistence (or repository) and Service.

  • So Domain contains basically POJO classes. Inside the Domain, there is another package for the Repository (its interfaces and their implementations)

  • The Service contains interfaces and their implementations BUT here, services implementation classes call Repository objects and kind of repeat their methods. But they also said the more the business logic is complex, some other methods can be added to service classes. So Repository is just their for CRUD and service is there to give access to CRUD + more depending of business logic...

Did I understand it properly ? But why to they use all those interfaces ? Just implementations would be sufficient in my view. Why does it look like DAO ? The only difference here is that I don't see where different database implementation can be adapted as DAO factory does...

Can you help me better understand Domain, Persistence, Service architecture ?

  • Read this as well books.google.com/books/about/…
    – Kyslik
    Commented Nov 25, 2017 at 12:53
  • @Kyslik Which part for this specific query ? Commented Nov 25, 2017 at 13:13
  • You need to get a grounding in software engineering theory rather than trying to find a recipe to follow. That book is about a specific technology. A first place to start would be an indepth look at a couple of design patterns to understand why the design pattern exists, what problems it solves, what problems it does not solve, and alternative ways of instantiating the design pattern in actual source code. A grasp of basic UML would help. Fundamental software engineering concepts such as coupling and cohesion and how OOP helps with those concepts would be great as well. Commented Nov 25, 2017 at 13:59
  • @RichardChambers Woah... You wan me to go back in college ? lol I know UML. I studied design patterns at school also. An analogy to my situation would be : " I've driven lots of cars but now I think I've been driving them on inappropriate races... Mostly because I did not know the cars nor the races requirements ". So for "Domain Persistence and Service" I learned a little bit what kind of "car" it is and little less what kind of "race" it's best suited for....That why I came and ask my question... Commented Nov 25, 2017 at 14:19

1 Answer 1


The Service contains interfaces and their implementations BUT here, services implementation classes call Repository objects and kind of repeat their methods.

Then the book isn't explaining it right. The purpose of the repository is to provide CRUD methods. The purpose of the services implementation is to provide methods that embody business operations.

For example, the PrintInvoice() method in the services implementation must retrieve invoice header, invoice line items, shipping address and billing address from the repository.

Passing CRUD methods through the service layer provides strict separation of layers, but I don't like that because it pollutes the service layer with unnecessary methods, methods that I can simply go to the repository for.

Why do they use all those interfaces?

To allow different implementations. Without the interface you would be bound to a single implementation. Having interfaces allows you to, for example, swap out the working implementation with a stub or mock for testing purposes.

  • Thank you. So I was on the right track then... For strict separation of layers, I understand that most calls will be done through services even though repository is sole responsible of CRUD right ? Does that way of organizing classes has more advantages over DAO ? I read somewhere else (possibly that book again) that DAO was kinda old school and was not offering better flexibility (or more) that this... Commented Nov 25, 2017 at 17:39
  • What does DAO mean in this specific context? Commented Nov 26, 2017 at 1:08
  • I mean does the way DAO organizes classes has appeared to solve issues in a less efficient manner hence the organization with Domain-Repository-Services ? Commented Nov 26, 2017 at 16:10
  • I mean, what is DAO? Is it Microsoft Data Access Objects? A J2EE Data Access Object? Decentralized Autonomous Organization? Commented Nov 26, 2017 at 16:17
  • Decentralized Autonomous Organization hahaha that's funny. Ok I got you now. I meant J2EE Data Access Object Commented Nov 27, 2017 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.