3. Definition
• A Facade Pattern says that just "just provide a unified and simplified
interface to a set of interfaces in a subsystem, therefore it hides the
complexities of the subsystem from the client".
• In other words, Facade Pattern describes a higher-level interface that
makes the sub-system easier to use.
• Practically, every Abstract Factory is a type of Facade.
• This pattern involves a single class which provides simplified methods
which are required by client and delegates calls to existing system
classes methods.
• It comes under “Structural Design Patterns” category.
Mudasir Qazi - mudasirqazi00@gmail.com 312-Dec-14
6. Advantages and Usage
• Advantages
1. It shields the clients from the complexities of the sub-system components.
2. It promotes loose coupling between subsystems and its clients.
• Usage
1. When you want to provide simple interface to a complex sub-system.
2. When several dependencies exist between clients and the implementation
classes of an abstraction.
3. Login in complex organizations like google, Microsoft’s accounts.
Mudasir Qazi - mudasirqazi00@gmail.com 612-Dec-14
7. UML – Sequence Diagram
Note the differences between ‘Before’
and ‘after’ event sequence.
In first case, each time client need to
interact with System it has to interact
with 3 separate sub systems.
In Second case, client just interact
with Façade and it manages all
internal affairs.
Mudasir Qazi - mudasirqazi00@gmail.com 712-Dec-14
8. Implementation (C# and Java)
• We are going to implement following system class diagram.
Each time we need to create a
‘Shape’, we just interact with
ShapeMaker (Façade) and it will
manage the internal
complexities.
Mudasir Qazi - mudasirqazi00@gmail.com 812-Dec-14
9. Step 1
• Create an interface to enforce common method.
In our example it would be Shape interface containing a method
draw.
Mudasir Qazi - mudasirqazi00@gmail.com 912-Dec-14
11. Step 3
Façade class acts as a
wrapper class which
contains all sub systems. In
our example it will contain
Circle, Rectangle and Square
type of objects.
Then you can have different
necessary methods.
Mudasir Qazi - mudasirqazi00@gmail.com 1112-Dec-14
12. Step 4
• Use Façade class to use sub systems (to draw different shapes).
Mudasir Qazi - mudasirqazi00@gmail.com 1212-Dec-14