Facade Design Pattern
Design Patterns
● Design patterns are used to represent some of the best practices adapted
by experienced object-oriented software developers.
● A design pattern systematically names, motivates, and explains a general
design that addresses a recurring design problem in object-oriented
systems.
● It describes the problem, the solution, when to apply the solution, and its
consequences.
Design Patterns
● It also gives implementation hints and examples.
● The patterns typically show relationships and interactions between classes
or objects.
● The idea is to speed up the development process by providing tested,
proven development paradigm.
Goal of Design Patterns
○ Understand the problem and matching it with some pattern.
○ Re Usage of old interface
○ Making the present design reusable for the future usage
Types of Design Patterns
○ Creational
■ These design patterns are all about class instantiation or object creation. Trying to
create objects in a manner suitable to the situation
■ Eg: Factory Method,Builder, Singleton
○ Behavioral
■ Behavioral patterns are about identifying common communication patterns between
objects and realize these patterns.
■ Eg: Command, Interpreter, Iterator
Types of Design Patterns
○ Structural
■ These design patterns are about organizing different classes and
objects to form larger structures and provide new functionality.
■ Eg:Adapter, Bridge,Facade
Facade Design Pattern
Facade design pattern
● Facade is a part of Gang of Four design pattern (23 others).
● As the name suggests, it means the face of the building.
● The people walking past the road can only see this glass face of the
building.
● They do not know anything about it, the wiring, the pipes and other
complexities.
● It hides all the complexities of the building and displays a friendly face.
Facade design pattern
● Same goes for the Facade Design Pattern. It hides the complexities of the
system and provides an interface to the client from where the client can
access the system.
Facade Design Pattern
Facade Design Pattern
When Should this pattern be used?
● The facade pattern is appropriate when you have a complex system that you
want to expose to clients in a simplified way
● or you want to make an external communication layer over an existing
system which is incompatible with the system.
● Facade deals with interfaces, not implementation.
● Its purpose is to hide internal complexity behind a single interface that
appears simple on the outside.
When Should this pattern be used?
● It deals with how your code should be structured to make it easily intelligible
and keep it well maintained in the long term.
Problem
Let's assume that you have a few operations to be made in sequence, and that
the same action is required in multiple places within your application. You have
to place the same code again and again in different places. You have done that,
but after a few days you find that something needs to be changed in that code.
Do you see the problem? We have to introduce the changes in all of the places
that the code exists. It's painful, isn't it?
Solution
As a solution, what you should be doing is to create a lead controller, which
handles all of the repeating code. From the calling point of view, we will just call
the lead controller to perform actions based on the parameters provided.
Now if we need to introduce any change in the process, then we will just need to
change the lead controller instead of making the change in all places where we
used that code.
Code Example
In this section we will see one more example, which is very common for
websites, of course with a code example. We will see an implementation of the
facade design pattern using a product checkout process. But before checking
perfect code with the facade pattern, let's have a look at some code that has a
problem.
Code Example
A simple checkout process includes the following steps:
1. Add product to cart.
2. Calculate shipping charge.
3. Calculate discount.
4. Generate order.
Code Example - Simple CheckOut Process
$productID = $_GET['productId'];
$qtyCheck = new productQty();
if($qtyCheck->checkQty($productID) > 0) {
$addToCart = new addToCart($productID); // Add Product to Cart
$shipping = new shippingCharge(); // Calculate Shipping Charge
$shipping->updateCharge();
Code Example - Simple CheckOut Process
$discount = new discount(); // Calculate Discount Based on
$discount->applyDiscount();
$order = new order();
$order->generateOrder();
}
Code Example - Simple CheckOut Process
In the above code, you will find that the checkout procedure includes various
objects that need to be produced in order to complete the checkout operation.
Imagine that you have to implement this process in multiple places. If that's the
case, it will be problematic when the code needs to be modified. It's better to
make those changes in all places at once.
Code Example - Facade design checkout process
We will write the same thing with the facade pattern, which makes the same
code more maintainable and extendable.
Code Example - Facade design checkout process
class productOrderFacade {
public $productID = '';
public function __construct($pID) {
$this->productID = $pID;
}
Code Example - Facade design checkout process
private function addToCart () {
/* .. add product to cart .. */
}
Code Example - Facade design checkout process
private function qtyCheck() {
$qty = 'get product quantity from database';
if($qty > 0) {
return true;
} else {
return true;
}
}
Code Example - Facade design checkout process
private function calulateShipping() {
$shipping = new shippingCharge();
$shipping->calculateCharge();
}
private function applyDiscount() {
$discount = new discount();
$discount->applyDiscount();
}
Code Example - Facade design checkout process
private function placeOrder() {
$order = new order();
$order->generateOrder();
}
Code Example - Facade design checkout process
public function generateOrder() {
if($this->qtyCheck()) {
$this->addToCart();// Add Product to Cart
$this->calulateShipping();// Calculate Shipping Charge
$this->applyDiscount();// Calculate Discount if any
$this->placeOrder();// Place and confirm Order
}
}
Code Example - Facade design checkout process
As of now, we have our product order facade ready. All we have to do is use it
with a few communication channels of code, instead of a bunch of code as
expressed in the previous part.
Please check the amount of code below which you will need to invest in order to
have a checkout process at multiple positions.
Code Example - Facade design checkout process
// Note: We should not use direct get values for Database queries to prevent SQL
injection
$productID = $_GET['productId'];
// Just 2 lines of code in all places, instead of a lengthy process everywhere
$order = new productOrderFacade($productID);
$order->generateOrder();
Code Example - Facade design checkout process
Now imagine when you need to make alterations in your checkout process. Now
you simply create changes in the facade class that we have created, rather than
introducing changes in every place where it has been applied.
THANK YOU

More Related Content

PDF
Space frame
PPT
Adapter pattern
PPTX
Decorator design pattern
PDF
Lighting design
PDF
Facade Research Document
PPTX
150316 case studies
PDF
Phân tích và thiết kế hệ thống quản lý bán hàng
PPSX
Observer design pattern
Space frame
Adapter pattern
Decorator design pattern
Lighting design
Facade Research Document
150316 case studies
Phân tích và thiết kế hệ thống quản lý bán hàng
Observer design pattern

What's hot (20)

PPTX
Facade pattern presentation(.pptx)
PDF
Presentation facade design pattern
PPT
Facade pattern
PDF
Introduction to Design Pattern
PPTX
Facade Pattern
PPTX
Design pattern-presentation
PPTX
Factory Method Pattern
PDF
Builder Design Pattern (Generic Construction -Different Representation)
PDF
Design patterns
PPTX
Design Pattern - Singleton Pattern
PPTX
Design pattern - Facade Pattern
PPTX
Let us understand design pattern
PDF
Design Patterns Presentation - Chetan Gole
PPTX
Software design patterns ppt
PDF
Design patterns tutorials
PDF
Factory Design Pattern
PPTX
Decorator Pattern
PPT
Design Patterns
PPT
Software Design Patterns
PPTX
Design pattern
Facade pattern presentation(.pptx)
Presentation facade design pattern
Facade pattern
Introduction to Design Pattern
Facade Pattern
Design pattern-presentation
Factory Method Pattern
Builder Design Pattern (Generic Construction -Different Representation)
Design patterns
Design Pattern - Singleton Pattern
Design pattern - Facade Pattern
Let us understand design pattern
Design Patterns Presentation - Chetan Gole
Software design patterns ppt
Design patterns tutorials
Factory Design Pattern
Decorator Pattern
Design Patterns
Software Design Patterns
Design pattern
Ad

Similar to Facade Design Pattern (20)

PPTX
Software Design principales
PDF
L05 Design Patterns
PPTX
Design patterns
PDF
Turku loves-storybook-styleguidist-styled-components
PPTX
SAD10 - Refactoring
PPT
Refactoring Tips by Martin Fowler
PDF
Design patterns for fun and profit
PDF
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
PPT
5 Design Patterns Explained
PPTX
Behaviour driven development aka bdd
PPTX
An Introduction to Domain Driven Design in PHP
PPTX
Design Patterns
PPTX
Javascript Design Patterns
PPTX
BDD Selenium for Agile Teams - User Stories
ODP
New Ideas for Old Code - Greach
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
PPTX
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
PDF
Build Your Own Angular Component Library
PDF
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
PDF
Finding the Right Testing Tool for the Job
Software Design principales
L05 Design Patterns
Design patterns
Turku loves-storybook-styleguidist-styled-components
SAD10 - Refactoring
Refactoring Tips by Martin Fowler
Design patterns for fun and profit
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
5 Design Patterns Explained
Behaviour driven development aka bdd
An Introduction to Domain Driven Design in PHP
Design Patterns
Javascript Design Patterns
BDD Selenium for Agile Teams - User Stories
New Ideas for Old Code - Greach
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Build Your Own Angular Component Library
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Finding the Right Testing Tool for the Job
Ad

More from Livares Technologies Pvt Ltd (20)

PPTX
Web Performance Optimization
PPTX
Supervised Machine Learning
PPTX
Software Architecture Design
PPTX
Automation using Appium
PPTX
Bubble(No code Tool)
PPTX
Unsupervised Machine Learning
PPTX
Developing Secure Apps
PPTX
Micro-Frontend Architecture
PPTX
PPTX
Introduction to Angular JS
PPTX
An Insight into Quantum Computing
PPTX
Just in Time (JIT)
PPTX
Introduction to Bitcoin
PPT
Data Mining Technniques
PPTX
Manual Vs Automation Testing
PPT
Screenless display
PPTX
Database Overview
PPTX
An Introduction to Machine Learning
PPTX
An Introduction to Face Detection
PDF
Smart water meter solutions using LoRa WAN - Troncart
Web Performance Optimization
Supervised Machine Learning
Software Architecture Design
Automation using Appium
Bubble(No code Tool)
Unsupervised Machine Learning
Developing Secure Apps
Micro-Frontend Architecture
Introduction to Angular JS
An Insight into Quantum Computing
Just in Time (JIT)
Introduction to Bitcoin
Data Mining Technniques
Manual Vs Automation Testing
Screenless display
Database Overview
An Introduction to Machine Learning
An Introduction to Face Detection
Smart water meter solutions using LoRa WAN - Troncart

Recently uploaded (20)

PDF
UiPath Agentic Automation session 1: RPA to Agents
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PPT
Geologic Time for studying geology for geologist
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
STKI Israel Market Study 2025 version august
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Configure Apache Mutual Authentication
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Getting started with AI Agents and Multi-Agent Systems
PPT
What is a Computer? Input Devices /output devices
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
Build Your First AI Agent with UiPath.pptx
UiPath Agentic Automation session 1: RPA to Agents
TEXTILE technology diploma scope and career opportunities
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Geologic Time for studying geology for geologist
1 - Historical Antecedents, Social Consideration.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
STKI Israel Market Study 2025 version august
Custom Battery Pack Design Considerations for Performance and Safety
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
CloudStack 4.21: First Look Webinar slides
Configure Apache Mutual Authentication
sustainability-14-14877-v2.pddhzftheheeeee
Developing a website for English-speaking practice to English as a foreign la...
NewMind AI Weekly Chronicles – August ’25 Week III
Getting started with AI Agents and Multi-Agent Systems
What is a Computer? Input Devices /output devices
A review of recent deep learning applications in wood surface defect identifi...
Comparative analysis of machine learning models for fake news detection in so...
Build Your First AI Agent with UiPath.pptx

Facade Design Pattern

  • 2. Design Patterns ● Design patterns are used to represent some of the best practices adapted by experienced object-oriented software developers. ● A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. ● It describes the problem, the solution, when to apply the solution, and its consequences.
  • 3. Design Patterns ● It also gives implementation hints and examples. ● The patterns typically show relationships and interactions between classes or objects. ● The idea is to speed up the development process by providing tested, proven development paradigm.
  • 4. Goal of Design Patterns ○ Understand the problem and matching it with some pattern. ○ Re Usage of old interface ○ Making the present design reusable for the future usage
  • 5. Types of Design Patterns ○ Creational ■ These design patterns are all about class instantiation or object creation. Trying to create objects in a manner suitable to the situation ■ Eg: Factory Method,Builder, Singleton ○ Behavioral ■ Behavioral patterns are about identifying common communication patterns between objects and realize these patterns. ■ Eg: Command, Interpreter, Iterator
  • 6. Types of Design Patterns ○ Structural ■ These design patterns are about organizing different classes and objects to form larger structures and provide new functionality. ■ Eg:Adapter, Bridge,Facade
  • 8. Facade design pattern ● Facade is a part of Gang of Four design pattern (23 others). ● As the name suggests, it means the face of the building. ● The people walking past the road can only see this glass face of the building. ● They do not know anything about it, the wiring, the pipes and other complexities. ● It hides all the complexities of the building and displays a friendly face.
  • 9. Facade design pattern ● Same goes for the Facade Design Pattern. It hides the complexities of the system and provides an interface to the client from where the client can access the system.
  • 12. When Should this pattern be used? ● The facade pattern is appropriate when you have a complex system that you want to expose to clients in a simplified way ● or you want to make an external communication layer over an existing system which is incompatible with the system. ● Facade deals with interfaces, not implementation. ● Its purpose is to hide internal complexity behind a single interface that appears simple on the outside.
  • 13. When Should this pattern be used? ● It deals with how your code should be structured to make it easily intelligible and keep it well maintained in the long term.
  • 14. Problem Let's assume that you have a few operations to be made in sequence, and that the same action is required in multiple places within your application. You have to place the same code again and again in different places. You have done that, but after a few days you find that something needs to be changed in that code. Do you see the problem? We have to introduce the changes in all of the places that the code exists. It's painful, isn't it?
  • 15. Solution As a solution, what you should be doing is to create a lead controller, which handles all of the repeating code. From the calling point of view, we will just call the lead controller to perform actions based on the parameters provided. Now if we need to introduce any change in the process, then we will just need to change the lead controller instead of making the change in all places where we used that code.
  • 16. Code Example In this section we will see one more example, which is very common for websites, of course with a code example. We will see an implementation of the facade design pattern using a product checkout process. But before checking perfect code with the facade pattern, let's have a look at some code that has a problem.
  • 17. Code Example A simple checkout process includes the following steps: 1. Add product to cart. 2. Calculate shipping charge. 3. Calculate discount. 4. Generate order.
  • 18. Code Example - Simple CheckOut Process $productID = $_GET['productId']; $qtyCheck = new productQty(); if($qtyCheck->checkQty($productID) > 0) { $addToCart = new addToCart($productID); // Add Product to Cart $shipping = new shippingCharge(); // Calculate Shipping Charge $shipping->updateCharge();
  • 19. Code Example - Simple CheckOut Process $discount = new discount(); // Calculate Discount Based on $discount->applyDiscount(); $order = new order(); $order->generateOrder(); }
  • 20. Code Example - Simple CheckOut Process In the above code, you will find that the checkout procedure includes various objects that need to be produced in order to complete the checkout operation. Imagine that you have to implement this process in multiple places. If that's the case, it will be problematic when the code needs to be modified. It's better to make those changes in all places at once.
  • 21. Code Example - Facade design checkout process We will write the same thing with the facade pattern, which makes the same code more maintainable and extendable.
  • 22. Code Example - Facade design checkout process class productOrderFacade { public $productID = ''; public function __construct($pID) { $this->productID = $pID; }
  • 23. Code Example - Facade design checkout process private function addToCart () { /* .. add product to cart .. */ }
  • 24. Code Example - Facade design checkout process private function qtyCheck() { $qty = 'get product quantity from database'; if($qty > 0) { return true; } else { return true; } }
  • 25. Code Example - Facade design checkout process private function calulateShipping() { $shipping = new shippingCharge(); $shipping->calculateCharge(); } private function applyDiscount() { $discount = new discount(); $discount->applyDiscount(); }
  • 26. Code Example - Facade design checkout process private function placeOrder() { $order = new order(); $order->generateOrder(); }
  • 27. Code Example - Facade design checkout process public function generateOrder() { if($this->qtyCheck()) { $this->addToCart();// Add Product to Cart $this->calulateShipping();// Calculate Shipping Charge $this->applyDiscount();// Calculate Discount if any $this->placeOrder();// Place and confirm Order } }
  • 28. Code Example - Facade design checkout process As of now, we have our product order facade ready. All we have to do is use it with a few communication channels of code, instead of a bunch of code as expressed in the previous part. Please check the amount of code below which you will need to invest in order to have a checkout process at multiple positions.
  • 29. Code Example - Facade design checkout process // Note: We should not use direct get values for Database queries to prevent SQL injection $productID = $_GET['productId']; // Just 2 lines of code in all places, instead of a lengthy process everywhere $order = new productOrderFacade($productID); $order->generateOrder();
  • 30. Code Example - Facade design checkout process Now imagine when you need to make alterations in your checkout process. Now you simply create changes in the facade class that we have created, rather than introducing changes in every place where it has been applied.