Facade pattern
One simple class in front of a group of classes, offering a few high-level methods for the common tasks.
Definition
A facade coordinates a subsystem (several services that must be called in the right order) behind methods named after what callers want, such as placeOrder(cart). It owns the sequence of steps and what happens when one fails, but holds no business rules of its own. The subsystem stays available for callers that need more control. A facade that collects every method of every subsystem turns into a god object.
In practice
CheckoutFacade.placeOrder reserves stock, charges the card, creates the order and releases the stock if payment fails.
Related terms
- AdapterA wrapper that makes a class with a different interface usable through the interface your code expects.
- Decorator patternWrapping an object in another object with the same interface to add behavior, without changing the original.
- Proxy patternA stand-in with the same interface as an object, which controls when and whether calls reach it.