Provide a unified interface to a set of interfaces in a subsystem, defining a higher-level interface that makes the subsystem easier to use. Use it when you want to provide a simple interface to a complex subsystem, when there are many dependencies between clients and implementation classes, or when you want to layer your subsystems with a defined entry point.
Examples:
- When you call a shop to place an order by phone, the operator is your facade — one simple voice interface that routes your request to the ordering system, payment gateway, and delivery service behind the scenes. In code, a VideoConversionFacade exposes a single encode(filename, format) method that internally orchestrates dozens of video-library objects.
// Facade unifies a compiler subsystem behind one class
class Compiler {
public:
Compiler();
virtual void Compile(istream& input, BytecodeStream& output) {
Scanner scanner(input);
ProgramNodeBuilder builder;
Parser parser;
parser.Parse(scanner, builder);
RISCCodeGenerator generator(output);
ProgramNode* parseTree = builder.GetRootNode();
parseTree->Traverse(generator);
}
};