SlideShare a Scribd company logo
1 of 31
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.
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

What's hot

Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 

What's hot (20)

Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Generics
GenericsGenerics
Generics
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Java program structure
Java program structure Java program structure
Java program structure
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Similar to Facade Design Pattern

Design patterns
Design patternsDesign patterns
Design patternsnisheesh
 
Turku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsTurku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsJames Stone
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
Design patterns for fun and profit
Design patterns for fun and profitDesign patterns for fun and profit
Design patterns for fun and profitNikolas Vourlakis
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 
5 Design Patterns Explained
5 Design Patterns Explained5 Design Patterns Explained
5 Design Patterns ExplainedPrabhjit Singh
 
Behaviour driven development aka bdd
Behaviour driven development aka bddBehaviour driven development aka bdd
Behaviour driven development aka bddPrince Gupta
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPChris Renner
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesSauce Labs
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteRavi Bhadauria
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Chris Laning
 
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Codemotion
 
Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component LibraryCarlo Bonamico
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobCiaranMcNulty
 

Similar to Facade Design Pattern (20)

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

More from Livares Technologies Pvt Ltd

Smart water meter solutions using LoRa WAN - Troncart
Smart water meter solutions using LoRa WAN - TroncartSmart water meter solutions using LoRa WAN - Troncart
Smart water meter solutions using LoRa WAN - TroncartLivares Technologies Pvt Ltd
 

More from Livares Technologies Pvt Ltd (20)

Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
 
Supervised Machine Learning
Supervised Machine LearningSupervised Machine Learning
Supervised Machine Learning
 
Software Architecture Design
Software Architecture DesignSoftware Architecture Design
Software Architecture Design
 
Automation using Appium
Automation using AppiumAutomation using Appium
Automation using Appium
 
Bubble(No code Tool)
Bubble(No code Tool)Bubble(No code Tool)
Bubble(No code Tool)
 
Unsupervised Machine Learning
Unsupervised Machine LearningUnsupervised Machine Learning
Unsupervised Machine Learning
 
Developing Secure Apps
Developing Secure AppsDeveloping Secure Apps
Developing Secure Apps
 
Micro-Frontend Architecture
Micro-Frontend ArchitectureMicro-Frontend Architecture
Micro-Frontend Architecture
 
Apache J meter
Apache J meterApache J meter
Apache J meter
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
An Insight into Quantum Computing
An Insight into Quantum ComputingAn Insight into Quantum Computing
An Insight into Quantum Computing
 
Just in Time (JIT)
Just in Time (JIT)Just in Time (JIT)
Just in Time (JIT)
 
Introduction to Bitcoin
Introduction to Bitcoin Introduction to Bitcoin
Introduction to Bitcoin
 
Data Mining Technniques
Data Mining TechnniquesData Mining Technniques
Data Mining Technniques
 
Manual Vs Automation Testing
Manual Vs Automation TestingManual Vs Automation Testing
Manual Vs Automation Testing
 
Screenless display
Screenless displayScreenless display
Screenless display
 
Database Overview
Database OverviewDatabase Overview
Database Overview
 
An Introduction to Machine Learning
An Introduction to Machine LearningAn Introduction to Machine Learning
An Introduction to Machine Learning
 
An Introduction to Face Detection
An Introduction to Face DetectionAn Introduction to Face Detection
An Introduction to Face Detection
 
Smart water meter solutions using LoRa WAN - Troncart
Smart water meter solutions using LoRa WAN - TroncartSmart water meter solutions using LoRa WAN - Troncart
Smart water meter solutions using LoRa WAN - Troncart
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

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.
  • 10.
  • 11.
  • 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.