Façade Design Pattern Source: Design Patterns – Elements of Reusable ObjectOriented Software; Gamma, et. al. Problem • A subsystem contains lots of classes, all of which are necessary to perform its function • Most of the subsystem's internal complexity is not directly relevant to its clients • We want to simplify the client's interface to the subsystem to make it easier to use • We want to minimize client dependencies on the subsystem's internal details Solution • Introduce a Façade object that provides a simplified interface to the subsystem • The Façade's interface provides exactly those operations needed by most clients, and no more • The Façade translates high-level client requests into lower-level requests on subsystem objects • Internal subsystem objects have no knowledge of the Façade Solution • Most clients interact with the subsystem strictly through the Façade • Advanced clients may still be allowed to access the full scope of subsystem functionality, but most clients don't need or want to • Similar to keeping a class' implementation details private, and making public only those operations directly needed by clients (i.e., information hiding) Consequences • Makes using the subsystem easier • Reduces coupling between clients and the subsystem • Reduces compilation dependencies, thus minimizing recompilation time • Useful for defining the interfaces between layers in a layered system Known Uses: Compilers Known Uses: Web Applications Application Server Browser Web Server Database Server Facade Known Uses: CS240 Chess Program Chess User Interface Facade Chess Logic XML Reading/Writing GTK GUI Toolkit Linux Hardware Known Uses: CS240 Chess Program Game PieceSelector has 1 Chess 1 +Game(in selector : PieceSelector) +Game(in fileName, in selector : PieceSelector) +GetTurn() : ChessColor +IsCheck() : bool +IsMate() : bool +GetColor(in pos : BoardPosition) : ChessColor +GetPiece(in pos : BoardPosition) : Piece +GetLegalMoves(in pos : BoardPosition) : <unspecified> +MakeMove(in pos : BoardPosition, in newPos : BoardPosition) : void +UndoMove() : void +Save(in fileName) : void has 1 1 has 1 contains 64 1 1 Board has 1 1 Square 1 1 XMLWriter BoardPosition has 1 XMLReader History PieceFactory contains 1 has * XMLEvent Move Piece «enumeration» XMLEventType «enumeration» ChessColor «enumeration» ChessDirection «enumeration» PieceType Pawn 0..1 Rook Knight Bishop King Queen
© Copyright 2026 Paperzz