Pergunta

At work, we are having 'arguments' about naming styles / conventions. Imagine having a service called UserSettingsService. This has 2 methods, one to get the user settings and one to save. Would you name the method to include what it does exactly, like .getUserSettings(), or just get()?

One argument is that the UserSettings part is implied in the service name. The other argument is that a full method name of getUserSettings() is unambiguos. Is there any 'correct' way to do this?

Foi útil?

Solução

The usual convention is not to repeat the class name in the method

ie Customer.CustomerName == bad

In your case, UserSettingsService sounds like a repository, which only contains user settings. So I would have methods like:

UserSettingsRepository.GetById(string id)
UserSettingsRepository.GetAll()

etc etc

If you have more than one type of settings you might include the type:

SettingsRepository.GetAllUserSettings();

Or you might have a 'resource':

SettingsRepository.UserSettings.GetAll();

Edit

Another method of resolving 'arguments' about naming conventions is to organize a Definitive Resolution in Naming Conventions Session. These session should take place in a pub. In order to propose or object to a naming standard you must first take a drink. Traditionally the oldest member of the team starts the meeting by proposing Hungarian Notation.

Licenciado em: CC-BY-SA com atribuição
scroll top