Introduction
I am trying to create a rather complex structure in Java with interfaces, abstract classes and generics. Having no experience working with generics and only average experience in creating good OOP constructs, this begins to prove a rather difficult task.
I have a feeling that what I'm trying to do cannot actually be done, but I can get closer to it. I will try to explain this as concise as possible. I just want to say right away that this structure will represent my DAOs and service levels for accessing the database. To make this question more abstract will only complicate the work.
My DAO layer is completely beautiful. There is a common DAO interface, and for each object there is a DAO interface that extends the general and populates the common types. Then there is an abstract class that is extended by each DAO implementation, which, in turn, implements the corresponding interface. The confusion is likely to read, so here is a diagram showing the DAO for products as an example:

Now for the service classes I had a similar design. Most methods in a class of service class apply to DAO methods anyway. If you replace each βDAOβ in the diagram above with βServiceβ, you will get the basis for my level of service. But there is one thing I want to do based on the following idea that I have
Each service class for an object will at least have access to one DAO object, namely the DAO of the object for which it is intended.
What...
Question / Problem
If I could create the right OO design so that each class of service has one instance variable for the DAO object of its corresponding object , my level of service would be ideal, in my opinion. Advice on this is welcome if my design is not as good as it seemed.
I implemented it as follows:
Class AbstractService
public abstract class AbstractService<EntityDAO> { EntityDAO entityDAO; public AbstractService() { entityDAO = makeEntityDAO();
Class ProductServiceImpl
public class ProductServiceImpl extends AbstractService<ProductDAOImpl> { public ProductServiceImpl() { super(); } @Override ProductDAOImpl makeEntityDAO() { return new ProductDAOImpl(); } }
The problem with this design is the compiler warning, which I don't like: it has an overridable method call in the constructor (see comment). Now it is designed to be overridden, in fact I am applying it to so that each class of service has a link to the corresponding DAO. Is this the best I can do
I did my best to include everything that you might need, and only what you need for this issue. All I have to say is that comments are welcome and extensive answers even more, thanks for taking the time to read.
Additional Resources in StackOverflow
Understanding Service Levels and DAO
DAO and Service Levels (JPA / Hibernate + Spring)