Domanda

I'm developing a web application with Spring MVC, Spring Data JPA and Hibernate, the data access part is taken care of by the repositories provided by Data JPA

However, I'm planning to have a generic service layer (atleast for the common operations), is it a good practise? Or is it advised to not generalise it?

È stato utile?

Soluzione

If your app is simple (mostly CRUD) operations then you can access your Repository classes directly.

If you have additional server-side business logic that needs to be applied to data or if you need to orchestrate multiple data access calls together then adding a Service layer would be appropriate.

Altri suggerimenti

If part of you application will consist of repeating same actions on different objects, it can make sense to have a generic abstract parent class for common operations.

You will have to decide if the gain in de-duplication of code is worth the complexity of the generic. There is no general rule ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top