Published on

[1] I wish I knew this earlier: The Art of Naming

I would always name my services / interfaces / handlers and everything else you can think of with the suffix ....Service.

Why?

I guess... Lack of maturity. Lack of experience. Nobody told me otherwise?

For instance:

  • UserService for managing user accounts.
  • SessionService for handling user sessions.
  • PermissionService for governing user permissions.

I really hope you can see that doesn't the Service part seem redundant? It doesn't enhance clarity. In fact, it often obfuscates the real purpose of the entity.


I wish I knew earlier that naming can be more descriptive, and there are alternatives that often make more sense.


To help fellow developers, here's a quick guide:

1. Third-party Service Integrations:
  • Instead of UserService, consider:
    • UserManager
    • UserHandler
    • UserConnector
2. Processing or Logic:
  • Instead of UserService, consider:
    • UserModifier
    • UserHandler
    • UserValidator (for validation logic)
3. Data Storage or Retrieval:
  • Instead of UserService, consider:
    • UserStore
    • UserRepository
    • UserArchive (if it's mainly for historical data)
4. Components that Transform Data:
  • Instead of UserService, consider:
    • UserTransformer
    • UserAdapter
    • UserConverter
5. Components Handling Caching:
  • Instead of UserService, consider:
    • UserCache
    • UserCacheProvider
6. Use-case Driven Naming:
  • Instead of UserService, consider:
    • UserAuthenticator
    • UserRegistrationProcessor
    • UserPasswordResetter
7. Configuration Components:
  • Instead of UserService, consider:
    • UserConfigProvider
    • UserSettings