Difference between List and and Return in Entity

Asked

Viewed 57 times

2

Hello, I am with a doubt when I will take the data of an SQL query, there is the possibility to pull by list and by Entity, which is would be the "most correct" or the usability of each?

public List<Usuario> buscarTodos(Usuario mod){...}

public Usuario pesquisarUsuario(Usuario mod) {...}
  • I believe it is self-explanatory. There are times when you need to seek only one result from your table public Usuario pesquisarUsuario(Usuario mod) {...}. And there are times you need to seek more than one. public List<Usuario> buscarTodos(Usuario mod){...}

  • I believe the answer lies in the name of methods.

  • Difference between List and Return in Entity !! It wouldn’t be [ Difference between Return List or Entity ]

1 answer

1


considering good practice, I believe that the first method is confusing and does not apply. Since you are passing a User parameter to list all users, I would use it like this:

public List<Usuario> buscarTodos(){...}

The second Method has more meaning, and by itself is already self-explanatory, ie, just looking at the signature is already understood for what it serves.

public List<Usuario> pesquisarUsuario(Usuario mod){...}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.