B
B
Biaci_Anj2022-04-02 13:22:08
Java
Biaci_Anj, 2022-04-02 13:22:08

What is the right thing to do in this situation of inheritance from GenericInterface?

I am doing a test project, there is a GenericDao interface, it has CRUD methods.

create()
findAll()
update()
delete()


But in each DAO, the find methods are different ( sometimes findPaginated - returns a page, sometimes findPaginatedSorted - a sorted page, sometimes just findSorted - a sorted list).

What is the right thing to do in such a situation?
I thought about several options:
1. Remove the findAll () method from GenericInterface
2. Implement it, but throw new UnsuportedOperationException in the body
3. Implement this method ( despite the fact that it is never used

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-04-02
@Biaci_Anj

The interface should not decide for the consumer - what is used, what is not used. So the real options here are:

  1. Put away. Quite a normal option if it's just a common part of specialized DAOs.
  2. Implement (used - not used, it doesn't matter)
  3. Supplement it with parameters that allow the consumer to decide what he wants to get - a specific page, the entire list, set sorting options, etc., that is, remove the need for specialized methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question