Question

Researching proper usage of Service classes.

Suppose, there are two Service Classes and corresponding DAOs : OrderService / DAO CustomerService / DAO

Now, in the OrderService, if some customer details are needed, should the access be via the CustomerService(which calls the CustomerDAO) or can the customer DAO itself be injected in the order service.

Are there any best practices / standards around this ? Do transactions have a bearing in scenarios like this ?

There were a few questions on SO around this but nothing that I could derive an answer from. Thanks in Advance.

Was it helpful?

Solution

If you want maximum decoupling then you should go through calling CustomerService, if the OrderService will be using the CustomerDAO many times then they are probably related and then it would be ok to inject the DAO directly to help diminish the overhead of going through the service everytime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top