A small method is a deliberately limited, cohesive unit of behavior. Keeping methods and classes small is a primary way to control complexity as code evolves: oversized units are harder to read, change, test, and extend, and they invite bugs because developers cannot easily grasp all their paths and cases. section 1.2.1 section 2.0
Size is not merely a line-count target. A method should do a clear, nameable action with requirements that are easy to see. When a segment inside a long method has its own purpose, extract it into a private method; keep it private when it is an implementation detail rather than behavior for other classes to invoke. section 2.1.1
Extract one cohesive action
Start with a public method that mixes several actions: validate input, calculate a result, and persist it. Move one meaningful segment at a time into helpers such as validateRequest(), calculateTotal(), and saveOrder(). The public method then communicates the overall flow, while each helper can be understood independently. Test private helpers through the public method; if isolated testing becomes necessary, move that behavior into another class. section 2.1.1 section 2.5
Use small methods and classes to make change safer, but avoid splitting mechanically:
- Read less implementation at a time; follow calls only when their details matter. section 2.1
- Replace or extend modeled pieces independently, and choose between isolated tests and tests of the assembled behavior. section 2.1
- Break multistep business flows into cohesive steps, using simpler workflow mechanisms unless flexibility or cross-service execution demands more. section 2.3.2
- Keep related code together when separation creates awkward signatures, offers little testing or replacement value, or leaves only a few helpers. Too many microclasses can also harm maintainability. section 2.1.3
- Treat dependency count as another dimension of size: a class with many dependencies may need to be broken down, while a new linked class can add coupling. section 4.3
Use the figure as a reminder that code tends to grow more complex over time unless its size is actively managed. section 1.2.1
Smallness supports cohesion but does not replace judgment about responsibility. The Single Responsibility Principle asks whether a unit has one reason to change; reducing size often makes that responsibility easier to see. Move new complexity away from stable units when adding features, rather than continually enlarging an existing method or class. section 2.3.2 section 2.5
