Implementing Naming Conventions

1. Naming Classes

TypeConventionExample
EntitySingular nounOrder, Customer
ServiceNoun + ServicePricingService
RepositoryEntity + RepositoryOrderRepository
DTO+ Request/ResponseCreateOrderRequest
Exception+ ExceptionOrderNotFoundException
TestClass + Test/ITOrderServiceTest

2. Naming Interfaces

StyleUse
Capability suffixComparable, Runnable
Role nounList, Repository
Avoid I prefixIUserService
Impl suffixAcceptable when one default exists: UserServiceImpl

3. Naming Methods

IntentVerb Prefix
Retrieveget, find (Optional), load
Createcreate, build, of
Mutateset, update, apply
Booleanis, has, can
Convertto, as, from
Actionhandle, process, execute

4. Naming Variables

ScopeStyle
LocalcamelCase, descriptive
Loop indexi, j OK for short loops
CollectionPlural: orders
Avoiddata, info, tmp, obj

5. Naming Constants

KindConvention
JavaUPPER_SNAKE_CASE static final
Enum valueUPPER_SNAKE_CASE
Magic numberReplace with named constant
GroupFinal class with private ctor

6. Naming Packages

ElementRule
FormatAll lowercase, dot-separated
Reverse domaincom.acme.order
No underscoresUse sub-package instead
Layered or featurePick one and stay consistent

7. Naming Test Classes

Test KindSuffix
Unit*Test
Integration*IT or *IntegrationTest
MethodmethodName_should_expected_when_state
BDDgiven...when...then...

8. Using Domain Language

PracticeEffect
Ubiquitous languageCode mirrors business terms
Avoid synonyms"Customer" or "Client", not both
GlossarySingle source of term definitions

9. Avoiding Hungarian Notation

BadGood
strNamename
iCountcount
lstUsersusers
Note: Modern IDEs and types make Hungarian prefixes redundant noise.

10. Using Intention-Revealing Names

Example: Reveal intent

// BAD
List<int[]> list1 = new ArrayList<>();
// GOOD
List<Cell> flaggedCells = new ArrayList<>();

11. Naming Boolean Variables

PrefixMeaning
isState: isActive
hasPossession: hasPermission
canCapability: canEdit
shouldDecision: shouldRetry
Avoid negationsisNotEmpty ❌ → use !isEmpty()

12. Naming Collections

TypeNaming
List/SetPlural noun: orders
MapkeyByValue or valueByKey: userById
Queue/StackAdd suffix: taskQueue