Video in progress

Strong Middle 🧭 Design patterns

How do you notice that a facade service is turning into a god class, and what do you do about it?

The signs: more than 8-10 dependencies in the constructor, a thousand-line class, and this file changes in every PR. A facade should only coordinate; once business rules start piling up inside it, you split it up by responsibility.

📖 Answer

A facade is a single simple entry point to a complex subsystem. For example, inside CheckoutFacade.checkout(cart) it calls the inventory, pricing, payment and delivery services in the right order. The controller knows one method, and that's all. This is good.

But a place where "everything goes through here" turns into a magnet. Half a year later CheckoutFacade has code for calculating discounts, building SMS text, and manually correcting stock levels.

The signs I look for:

  • the number of constructor parameters keeps growing;
  • the methods don't use each other, so the class is really several independent classes;
  • a unit test needs 10 mocks;
  • in the output of git log --format= --name-only | sort | uniq -c | sort -rn | head this file is in first place.

The cure is usually simple: move business rules back to the domain service or entity they belong to, and leave only "in what order to call" in the facade. If the facade serves several use cases, giving each its own class (PlaceOrder, CancelOrder) also works well: each one is small and tested on its own.