Item 40 - Design method signatures carefully

From Effective Java 2/e by Joshua Bloch

  • Choose method names carefully
  • Don’t go overboard in providing convenience methods
  • Avoid long parameter lists
    1. Break the method up into multiple methods
    2. Create helper classes to hold groups of parameters
    3. Combines aspects of the first two is to adapt the Builder pattern
  • For parameter types, favor interfaces over classes
  • Prefer two-element enum types to boolean parameters
    • public enum TemperatureScale { FAHRENHEIT, CELSIUS }

Posted by The Finest Artist