06 Facade
06 Facade
1
2
Facade Pattern
3
Watching a movie (the hard way)
4
Home Theater
5
Tasks in terms and
the method calls needed to perform them
6
The Facade simplifies this system
Client code now calls methods
on the home theater Facade
7
Facades and adapters may wrap multiple classes, but a
facade’s intent is to simplify, while an adapter’s is to
convert the interface to something different.
8
Constructing your home theater facade
9
Implementing the simplified interface
10
Time to watch a movie (the easy way)
11
Time to watch a movie (the easy way)
12
Facade Pattern UML Class diagram
13
The Facade and the Principle of Least Knowledge
14
Hiding the complexities of the system and providing an interface to the
client from where the client can access the system. 15
The hotel has a hotel keeper.
There are Veg, Non-Veg and Veg/Non Both restaurants.
A client wants to access to different menus of different restaurants .
You do not know what are the different menus they have.
You just have access to hotel keeper who knows his hotel well.
Whichever menu you want, you tell the hotel keeper and he gives it to you.
The hotel keeper acts as the facade, as he hides the complexities of the
system hotel.
16
17
18
19
In this way the implementation is sent to the facade.
The client is given just one interface and can access only that.
This will hide all complexities.
Pros
• You can isolate your code from the complexity of
subsystems.
Cons
• A facade can become a god object coupled to all classes
of an app.
21