Explains the real criteria for splitting methods and classes (one level of abstraction, one reason to change, cohesion), and the failure mode of over-splitting into tiny, scattered indirection.
Small is not a line count. A method is the right size when it works at one level of abstraction: it reads like a list of steps, each step named, with the details pushed into well-named helpers. A class is the right size when it has one reason to change and its fields are used together (high cohesion).
Split when a method mixes business steps with plumbing, when you feel the need for section comments, or when a class's fields fall into groups used by different methods. Don't split when the extracted piece has no better name than the code itself, or when the reader would have to jump through five two-line methods to follow one simple flow. The trade-off is locality versus abstraction: every split hides detail but adds a jump.
"I don't think of it as a line count. My test for a method is whether it works at one level of abstraction. A good
PlaceOrderAsyncreads like the business process: validate, reserve stock, take payment, save, publish an event. If in the middle of that I'm suddenly building a SQL string or formatting an email body, the method is mixing levels and that part should be extracted behind a name. Another strong signal is section comments like// calculate discounts: that comment wants to be a method name.For classes I look at cohesion: do all the methods use most of the fields? If half the methods use the repository and the email client and the other half use the PDF renderer, that's two classes sharing a file. And I look at reasons to change: if pricing changes and template changes both edit the same class, it should probably be split.
The mistake I see on the other side is over-splitting. Someone reads 'methods should be four lines' and you end up with
ValidateOrdercallingValidateLinescallingValidateLinecallingCheckQuantity, each in a different file, and to understand a ten-line rule you open six tabs. If the extracted method's name just repeats its body, it isn't hiding anything. My rule is that a split has to make the caller easier to read without making the callee harder to find."
| Signal | What to do |
|---|---|
| Method mixes business steps and low-level detail | Extract the detail behind an intention-revealing name |
| Section comments inside a method | Each section becomes a method named after the comment |
| Deep nesting (3+ levels) | Guard clauses, then extract the inner block |
| Class fields used by disjoint sets of methods | Extract class along the field groups |
| Two unrelated reasons to change | Split by responsibility |
| Hard to unit test one behaviour in isolation | Extract it so it can be tested |
| Signal | Why splitting hurts |
|---|---|
Extracted name restates the code (AddOneToCount) |
No information hidden, just an extra jump |
| Logic is a simple linear sequence that reads fine | The story is easier to follow in one place |
| Pieces always change together | Splitting creates shotgun surgery |
| Only one caller and the method is already short | Indirection without benefit |
| Measure | Rough guide |
|---|---|
| Method length | Fits on one screen (~20-30 lines) |
| Cyclomatic complexity | Aim under ~10; CA1502 warns at 25 by default |
| Parameters | More than 3-4 suggests a parameter object |
| Class coupling | CA1506 flags very high coupling (defaults 95 for types) |
A 220-line InvoiceService.Generate method mixed tax rules, PDF layout and email sending. Splitting it into InvoiceCalculator, InvoicePdfRenderer and InvoiceMailer let the team unit test GST rules for the first time (14 tests), and a later PDF template change no longer needed a review from the finance-rules owner.
Checks the candidate has judgment about decomposition rather than a memorised rule, and knows over-splitting is a real failure mode.
Green flags
Red flags
Human working memory holds a handful of items. A long method forces the reader to keep many variables and branches in mind at once. But the real cost driver is how many concepts the method juggles, not how many lines it has. A 40-line switch mapping enum values to strings is easy; a 15-line method with three nested loops and mutations is not.
PlaceOrderAsync <- business level: steps
├─ ValidateOrder <- rule level
├─ ReserveStockAsync <- integration level
│ └─ HttpClient... <- transport level
└─ SaveAsync <- persistence level
└─ SQL <- storage level
A method should sit on one row. When it reaches down two rows, extract.
Lack of Cohesion of Methods (LCOM) counts how many method pairs share no fields. High LCOM means the class is really several classes. You can eyeball it: draw which methods touch which fields; disconnected clusters are candidate classes.
Fields: _repo _mailer _pdf _taxRules
Calc() x x
Save() x
Render() x
Email() x x
=> clusters {Calc, Save}, {Render, Email}
Every extraction adds a jump. Jumps are cheap when the name tells you enough that you don't need to follow it (CalculateGst). They are expensive when you must follow them to understand anything (DoStep2). The JIT doesn't care: small methods are often inlined, so performance is rarely a reason to keep code long.
Code that changes together should live together. Splitting a concept across files by technical layer (one file for validation, one for mapping, one for rules) can make a simple change touch many files. Prefer splits along business concepts over splits by technical role.
dotnet_diagnostic.CA1502.severity = warning and lower the threshold via a CodeMetricsConfig.txt file containing CA1502: 10; see what lights up.An order placement method before and after extracting at one level of abstraction.
// Before: business steps mixed with plumbing.
public async Task
IncrementCounter). Why it is wrong: the reader gains nothing and pays a jump. Instead: only extract when the name hides meaningful detail.OrderValidator, OrderMapper, OrderHelper) for one simple feature. Why it is wrong: one business change now touches many files. Instead: split along business concepts and keep things that change together together.The senior framing is cost of a jump versus cost of a context switch. Extraction removes context switches (mixed levels) but adds jumps. A good extraction's name is trustworthy enough that the reader doesn't follow it. When you see people Ctrl+clicking through every helper to understand a flow, the code has been split past the point of usefulness.
It helps to know the classic types of cohesion (Constantine and Yourdon), from worst to best, because they tell you why a class feels wrong:
| Cohesion type | What groups the code | Example | Verdict |
|---|---|---|---|
| Coincidental | Nothing | Utils with string, date and HTTP helpers |
Split |
| Logical | Same category of thing | ExportService doing CSV, PDF and Excel via a flag |
Usually split by type |
| Temporal | Runs at the same time | StartupTasks doing cache warm-up, migrations, emails |
Split by purpose |
| Sequential / communicational | Output of one step feeds the next, or same data | InvoiceCalculator steps on one invoice |
Fine |
| Functional | Everything serves one well-defined task | GstCalculator |
Ideal |
What the framework gives you: IDE Extract Method/Class/Interface refactorings, CA1502 (complexity) and CA1506 (coupling) analysers, and Visual Studio's Code Metrics window. Use metrics to find hotspots, then use judgment.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Extract method | Mixed abstraction levels, section comments | Small, IDE-assisted | Name no better than the body |
| Extract class | Field clusters, two reasons to change | New type, DI registration | Pieces always change together |
| Inline method | Over-split, pointless indirection | Small | The method is reused or tested independently |
| Leave it long | Flat, linear, readable (e.g. a mapping) | None | It has branches and mutations |
Cohesion is how strongly the parts of a module belong together. A highly cohesive class has methods that work on the same data towards one purpose, so a change to that concept happens in one place. Low cohesion shows up as Utils or Manager classes with unrelated methods, fields that only one or two methods use, and classes that change for many different reasons. I improve it by grouping code around domain concepts and features, moving methods to the data they use, and splitting classes whose fields form separate clusters.
Over-engineering is complexity that today's requirements do not justify. I detect it through symptoms with numbers behind them: a one-field change touching many files, interfaces with one implementation, configuration options nobody sets, patterns like CQRS or event sourcing without the problems they solve, and microservices that always deploy together. I reverse it incrementally rather than with a rewrite: inline single-use abstractions, merge layers that only pass data through, consolidate services that share a release cycle, and delete unused options, each step behind tests. I also address why it happened, because otherwise it grows back.
How to tell it (STAR)
**S:** Our invoicing service had one [220]-line method that mixed tax rules, PDF layout and email, and every change to it was slow and risky. **T:** I was asked to [add a new invoice type] and decided to make the method safe to change first. **A:** I wrote characterisation tests with snapshots, then extracted step by step with the IDE refactorings, one small PR each, ending with three focused classes. I kept validation together rather than splitting it into tiny pieces because those rules always change together. **R:** The new invoice type took [2] days instead of the estimated [5], GST rules got [14] unit tests, and we had [no] invoicing defects in the following [quarter].
Last updated 23 Nov 2026.