Design Patterns Handbook
  • Introduction
  • Creational Patterns
    • Builder
    • Factory
    • Abstract Factory
    • Factory Method
    • Prototype
    • Singleton
    • Object Pool
    • Revealing Constructor
  • Structural Patterns
    • Adapter
    • Composite
    • Proxy
    • Flyweight
    • Facade
    • Bridge
    • Decorator
    • Private Class Data
  • Behavioral Patterns
    • Template Method
    • Mediator
    • Chain Of Responsibility
    • Observer
    • Strategy
    • Command
    • State
    • Visitor
    • Memento
    • Interpreter
    • Null Object
    • Iterator
    • Middleware
  • Clean Code Patterns
    • Extract Method
    • Clarify Responsibility
    • Remove Duplications
    • Keep Refactoring
    • Always Unit Test
    • Create Data Type
    • Comment to Better Name
    • Consistent Naming
    • If-else over ternary operator
    • Composition over Inheritance
    • Too Many Returns
    • Private to Interface
  • Anti Patterns
    • Big Ball of Mud
    • Singleton
    • Mad Scientist
    • Spaghetti Code
    • It Will Never Happen
    • Error Codes
    • Commented Code
    • Abbreviations
    • Prefixes
    • Over Patternized
    • Generic Interface over Function
Powered by GitBook
On this page

Was this helpful?

  1. Clean Code Patterns

Consistent Naming

The same things should be always use the same name in the code. Coding is not an writing exercise where we are asked to use as many synonym as possible to create high quality literature.

Look at that method variables. offset is renamed to startsWith and then renamed to startFrom. Then limit parameter is renamed to numItems and then howMany parameter.

class Controller {
  private Service service;

  Response listJobs(@RequestParam("offset") final int startsWith, @RequestParam("limit") int numItems) {
    return Response.from(service.find(startsWith, numItems)).build();
  }
}

class Service {
  List<User> find(int startFrom, int howMany) {
     return null; // return something...
  }
}
PreviousComment to Better NameNextIf-else over ternary operator

Last updated 5 years ago

Was this helpful?