View
216
Download
3
Category
Preview:
Citation preview
Façade Design PatternSource: Design Patterns – Elements of Reusable Object-
Oriented 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 WebServer Facade
DatabaseServer
Known Uses: CS240 Chess Program
Hardware
Linux
XML Reading/Writing GTK GUI Toolkit
Chess Logic
Chess User Interface
Facade
Known Uses: CS240 Chess Program
PieceSelector
Chess
+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
Game
1 1
has Board
History
11 has
1
1
hasSquare
1
64
contains
Move
1
*
contains
Piece
1
0..1
has
Pawn
BoardPosition
1 1
has
PieceFactory
1
1has
XMLReaderXMLWriter
XMLEvent
«enumeration»XMLEventType
«enumeration»ChessColor
«enumeration»ChessDirection
«enumeration»PieceType
Rook Knight Bishop King Queen
Recommended