4
4
4ex0V2016-08-24 16:26:03
Java
4ex0V, 2016-08-24 16:26:03

What is the correct way to name methods in Java?

Hello!
Please give your opinion on the following method naming in Java.
Let's say I have some DAO class:

public class DAO
{
   public Collection<Event> getEvents() { . . . }

   public Collection<Event> getEventsByTimerange(DateTime from, DateTime until) { . . . } 

   public Collection<Event> getEventsByPlace(String place) { . . . }
}

According to the Oracle documentation, the signature of a method is its name and parameters.
I think that you should use overloading and call methods like this so that the signature speaks for itself, i.e.:
public class DAO
{
   public Collection<Event> getEvents() { . . . }

   public Collection<Event> getEvents(DateTime from, DateTime until) { . . . } 

   public Collection<Event> getEvents(String place) { . . . }
}

This method name is more logical, and also allows you to quickly find what you need.
Maybe someone met arguments on this topic or is ready to express their competent opinion?
I will be glad to any answer. Thanks a lot!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Vitrenko, 2016-08-24
@Vestail

Joshua Bloch - Effective Java, Item 41.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question