Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

An OrderFacade class has grown to 3,000 lines and 80 public methods used by many controllers and jobs. Every change causes merge conflicts. What do you do?

The OrderFacade has stopped being a facade and become a god class that mixes many responsibilities, which is why every change collides with someone else's. I would first cover its behaviour with tests, then group its 80 methods by which callers use them, split those groups into small application services, one per feature or use case, and move business logic into the domain objects where it belongs. The old facade stays for a while as thin delegation so callers migrate gradually, and architecture tests enforce the new structure so it does not grow back.

Why this question is asked

Large facades rarely start large. A team creates OrderFacade to give controllers one entry point, and over three years every new feature adds two more methods, because the facade is where order code lives. At 3,000 lines, it is the most edited file in the repository, every pull request touches it, and nobody fully understands it. Interviewers ask this scenario because it tests practical refactoring: diagnosing the real problem, finding seams from data, changing structure without stopping delivery, and keeping the improvement. In this answer, we will diagnose the problem, find the groups of methods, protect behaviour with tests, split the class, migrate callers through delegation, and enforce the new shape.

1Diagnosing the Problem

A facade is meant to be a thin, simple entry point to a subsystem. A god class is a class that knows and does too much: it holds many unrelated responsibilities, has many dependencies, and is coupled to most of the system. OrderFacade with 80 public methods, used by many controllers and jobs, is the second. It probably has 15 to 25 injected dependencies, mixes order placement, cancellation, refunds, reporting, exports and admin fixes, and contains business rules that should be in Order itself.

The merge conflicts are the visible symptom. The underlying cost is that unrelated changes share one file and one set of tests, so a change to export formats can break refund logic, and reviewers cannot see the impact of a change because the class is too big to reason about.

2Grouping Methods by Their Callers

Instead of guessing how to split the class, we let usage tell us. For each public method we list its callers, which an IDE's find-usages or a small script over the code base can produce. Methods used by the same callers usually belong to the same use case, and they often share the same subset of dependencies.

Java
// Output of a usage scan over OrderFacade (simplified)
placeOrder, validateCart, applyCoupon, quoteShipping <- CheckoutController, MobileCheckoutController
cancelOrder, canCancel, cancelLineItem <- OrderController, CustomerSupportJob
refund, partialRefund, refundStatus <- RefundController, PaymentWebhookHandler
exportOrdersCsv, exportForAccounting, ordersReport <- ReportingController, NightlyExportJob
fixStuckOrder, forceStatus, resendConfirmation <- AdminController
// ... 80 methods fall into about 9 groups; 6 methods have no callers at all
Groups found in OrderFacade
GroupExample methodsMain callersTarget
CheckoutplaceOrder, applyCouponCheckout controllersCheckoutService
CancellationcancelOrder, canCancelOrderController, support jobCancellationService
Refundsrefund, partialRefundRefundController, webhookRefundService
Reporting and exportexportOrdersCsv, ordersReportReporting, nightly jobOrderReportingService
Admin fixesforceStatus, resendConfirmationAdminControllerOrderAdminService
No callers6 methodsNoneDelete

Notice the last line. Large facades usually contain dead methods; deleting them is the easiest win and reduces the class before any real refactoring starts. The git history adds a second signal: methods that are always changed together belong together, and the method groups that change most often are where conflicts come from, so they are the ones to extract first.

3Protecting Behaviour Before Moving Code

Moving code without tests is how refactoring creates incidents. Before splitting a group, we make sure its behaviour is covered at the facade's public methods, because those are what callers depend on. Where tests are missing, we write characterisation tests, tests that record what the code does today, right or wrong, so we notice any change. For a group like cancellation, that might be ten tests: cancel a paid order, cancel a shipped order, cancel twice, cancel one line item.

These tests are written against the facade's public methods, so they survive the refactoring unchanged and prove the move did not change behaviour.

4Splitting Into Use Case Services and Moving Logic Down

Each group becomes a small application service with only the dependencies it needs. While moving the code, we also move business rules into the domain objects. A rule such as an order can be cancelled only before it ships belongs in Order, not in a service, so every service that needs it uses the same rule.

Java
// Before, inside OrderFacade
public void cancelOrder(long id, String reason) {
Order o = orders.findById(id).orElseThrow();
if (o.getStatus() == Status.SHIPPED || o.getStatus() == Status.DELIVERED) throw new CannotCancel(id);
o.setStatus(Status.CANCELLED); o.setCancelReason(reason);
payments.voidAuthorisation(o.getPaymentId());
events.publish(new OrderCancelled(id));
}
// After: the rule lives in Order, the service coordinates
public class Order {
public void cancel(String reason) {
if (status == Status.SHIPPED || status == Status.DELIVERED) throw new CannotCancel(id);
status = Status.CANCELLED; cancelReason = reason;
}
}
@Service
class CancellationService { // three dependencies instead of twenty
@Transactional
public void cancelOrder(long id, String reason) {
Order o = orders.findById(id).orElseThrow();
o.cancel(reason);
payments.voidAuthorisation(o.paymentId());
events.publish(new OrderCancelled(id));
}
}

The new service is a proper facade again: a short coordinator for one use case. The domain object now protects its own invariant, and the rule can be unit tested without any service.

5Migrating Callers Through Thin Delegation

We do not change all callers at once. After a group is extracted, the old facade methods become one-line delegations to the new service, so every existing caller still works and the change is small and safe to merge.

Java
@Service
@Deprecated(forRemoval = true) // new code should call the use case services
public class OrderFacade {
private final CancellationService cancellation;
// ...
public void cancelOrder(long id, String reason) { cancellation.cancelOrder(id, reason); }
}
Step throughExtracting one group from OrderFacade
  1. Pick the group with most conflictsfrom caller scan and git history
  2. Add characterisation testsat the facade's public methods
  3. Create the use case servicemove code, push rules into domain objects
  4. Facade delegates to the new servicecallers unchanged, small safe merge
  5. Move callers as teams touch them
  6. Delete delegation without callersthen extract the next group

6 steps in order. Play them, or step through them one at a time.

Then callers move to the new services one by one, as their owning teams touch them; the deprecation warning reminds them. When a delegating method has no callers left, it is deleted. Over a few months the facade shrinks to nothing and is removed. Throughout, feature work continues, and the merge conflicts drop as soon as the busiest groups have moved out, because changes now land in different files.

6Enforcing the New Structure

Without a guard, the next urgent feature adds method 81 to whatever large class is nearest. So we add architecture tests, for example with ArchUnit: no new dependencies on OrderFacade from classes that do not use it today, application services must not depend on each other in cycles, and controllers may only depend on application services, not on repositories. A simple size check can also warn when a service passes, say, 15 public methods, which prompts a conversation before it becomes the next god class.

7Follow-up questions

Why not rewrite OrderFacade from scratch?

A rewrite of 3,000 lines that many teams depend on is a long, risky project that stops other work and usually loses rules nobody wrote down. Extracting one group at a time behind delegation keeps every step small, reviewable and reversible, and delivers benefits after the first extraction.

How do you handle methods shared by several groups?

Often they are domain logic in the wrong place and move into the domain object, where every service can use them. If they are genuine coordination shared by two use cases, a small shared component is fine, but it should not become a new facade.

What if two teams want to change the same group during the refactoring?

Coordinate the order: extract that group first, or freeze it briefly, a day or two, while the move happens. Because each extraction is small, the freeze is short, and afterwards both teams work in a smaller file with fewer conflicts.

8Conclusion

In this answer, we treated a 3,000-line OrderFacade as what it has become, a god class mixing many responsibilities. We grouped its methods by callers and change history, protected behaviour with characterisation tests at the public methods, split the groups into small use case services and moved business rules into domain objects. The old facade stayed as thin delegation so callers could migrate gradually, and architecture tests keep the new structure from growing back.

What to say in the interviewAbout 80 seconds aloud

Open with

At 80 public methods this isn't a facade any more, it's a god class: it mixes checkout, cancellation, refunds, reporting and admin fixes, probably with twenty dependencies, and every unrelated change lands in the same file, which is why we get the merge conflicts.

Then, if they want more

I wouldn't rewrite it. First I'd scan who calls each method; methods with the same callers form natural groups, and I'd expect around eight or ten groups plus some dead methods I can delete right away. Git history tells me which groups change most, and those go first.

Before moving a group, I'd make sure there are tests at the facade's public methods, adding characterisation tests where needed, so I can prove behaviour didn't change.

Then I'd extract each group into a small application service per use case, like a CancellationService with just the three dependencies it needs, and push business rules, such as when an order can be cancelled, down into the Order entity.

The old facade method becomes a one-line delegation, marked deprecated, so callers keep working and migrate as their teams touch them, and delegations without callers get deleted. Finally, ArchUnit rules stop new dependencies on the old facade and keep controllers talking to use case services, so it doesn't grow back.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "An OrderFacade class has grown to 3,000 lines and 80 public methods used by many...": https://scrivio-interview-library.netlify.app/java/structural-patterns/b1c0d5b217/