That’s an interesting question and I think it recurs in Stack. I will use as java language I have more domain, but this rule applies to any language since we are talking about Software Design.
DAO
As almost answer, you can base yourself on this other answer:
What is the difference between DAO and Repository?
A repository is bound by the application’s business rule and is
associated with the aggregation of your business objects and returns objects from
domain representing such data.
...
The DAO (Data Access Object) at first has its limited scope on
capture and persistence of data from an DTO (Data Transfer
Object) representing a database record, consequently
it transmits only the relational physical world of the database and not
represents the real business mini-world of your application.
What I don’t think was very coherent was her practical explanation. The perfect world of DAO should be exactly the basic operations we need to handle the data (regardless of whether the vendor is a relational database, archive or anything else that can maintain a state):
- recover
- add
- remove
- upgrade
- list (some people find this method unnecessary as it would be the same as a search without a search filter)
- list with a fileDPquery(which is a parameter, usually known as "Query Object")
Repository
This is the data that the business needs to obtain. We will request them to the DAO.
It usually has the same basic DAO methods (it is not a rule, you could limit the view in your software only to those methods that are called directly by the business layer, which is usually named with Service):
- recover
- add
- remove
- upgrade
- list
- list with a child
and the methods your business usually needs to obtain filtered data:
UsuarioFilter usuarioFilter = new UsuarioFilter();
usuarioFilter.setAtivo(true);
List<Usuario> usuariosAtivos = usuarioDAO.listar(usuarioFilter);
UsuarioFilter usuarioFilter = new UsuarioFilter();
usuarioFilter.getOrdersBy().add(UsuarioFilter.OrderBy.DATA_CADASTRO_DESC);
usuarioFilter.setLimit(1);
List<Usuario> usuarios = usuarioDAO.listar(usuarioFilter);
Usuario ultimoUsuarioCadastrado = usuarios.isEmpty() ? null : usuarios.iterator().next(); // ou usuarios.get(0);
The recommended scenario is Service -> Repository -> DAO
Here is a link to a more detailed explanation if you need.
Important references
Answer: Yes, it can. As for opinions, we try to avoid them and try to substantiate the answers with arguments, demonstrations and references. Would it be nice if you could say what you mean by DAO and what you understand by Repository. You can write here your definition or point out the references you are using. Also, what problem do you want to solve or what benefits do you expect from these Patterns? For now I only see here an opportunity for a chat and I do not see much potential to offer a good answer...
– Caffé