Implementing Naming Conventions
1. Naming Classes
| Type | Convention | Example |
| Entity | Singular noun | Order, Customer |
| Service | Noun + Service | PricingService |
| Repository | Entity + Repository | OrderRepository |
| DTO | + Request/Response | CreateOrderRequest |
| Exception | + Exception | OrderNotFoundException |
| Test | Class + Test/IT | OrderServiceTest |
2. Naming Interfaces
| Style | Use |
| Capability suffix | Comparable, Runnable |
| Role noun | List, Repository |
Avoid I prefix | IUserService ❌ |
| Impl suffix | Acceptable when one default exists: UserServiceImpl |
3. Naming Methods
| Intent | Verb Prefix |
| Retrieve | get, find (Optional), load |
| Create | create, build, of |
| Mutate | set, update, apply |
| Boolean | is, has, can |
| Convert | to, as, from |
| Action | handle, process, execute |
4. Naming Variables
| Scope | Style |
| Local | camelCase, descriptive |
| Loop index | i, j OK for short loops |
| Collection | Plural: orders |
| Avoid | data, info, tmp, obj |
5. Naming Constants
| Kind | Convention |
| Java | UPPER_SNAKE_CASE static final |
| Enum value | UPPER_SNAKE_CASE |
| Magic number | Replace with named constant |
| Group | Final class with private ctor |
6. Naming Packages
| Element | Rule |
| Format | All lowercase, dot-separated |
| Reverse domain | com.acme.order |
| No underscores | Use sub-package instead |
| Layered or feature | Pick one and stay consistent |
7. Naming Test Classes
| Test Kind | Suffix |
| Unit | *Test |
| Integration | *IT or *IntegrationTest |
| Method | methodName_should_expected_when_state |
| BDD | given...when...then... |
8. Using Domain Language
| Practice | Effect |
| Ubiquitous language | Code mirrors business terms |
| Avoid synonyms | "Customer" or "Client", not both |
| Glossary | Single source of term definitions |
9. Avoiding Hungarian Notation
| Bad | Good |
strName | name |
iCount | count |
lstUsers | users |
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
| Prefix | Meaning |
is | State: isActive |
has | Possession: hasPermission |
can | Capability: canEdit |
should | Decision: shouldRetry |
| Avoid negations | isNotEmpty ❌ → use !isEmpty() |
12. Naming Collections
| Type | Naming |
| List/Set | Plural noun: orders |
| Map | keyByValue or valueByKey: userById |
| Queue/Stack | Add suffix: taskQueue |