0% found this document useful (0 votes)
20 views

Lecture 12 - Facade Design Pattern

The document discusses the facade design pattern, including its definition, usage, UML diagram, and example in Java. The facade pattern provides a simplified interface to a subsystem, making it easier to use. It involves creating a unified interface on top of existing interfaces to simplify client usage.

Uploaded by

Iffat Nowshin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lecture 12 - Facade Design Pattern

The document discusses the facade design pattern, including its definition, usage, UML diagram, and example in Java. The facade pattern provides a simplified interface to a subsystem, making it easier to use. It involves creating a unified interface on top of existing interfaces to simplify client usage.

Uploaded by

Iffat Nowshin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Lecture 12

Kazi Rifat Ahmed


Lecturer
Department of Software Engineering
Daffodil International University
Facade Design Pattern
● What is Facade Pattern
● Usage of Facade Pattern

Outline ●

UML of Facade Pattern
Example of Facade Pattern
● Benefits of Facade Pattern
Facade Design Pattern
● The Facade Design Pattern is a structural pattern that provides a simplified
interface to a set of interfaces in a subsystem, making it easier to use.
● It involves creating a unified interface that sits on top of a set of interfaces
to simplify the usage for clients.
Facade Design Pattern
Facade Design Pattern
In the above diagram,

● Structuring a system into subsystems helps reduce complexity.


● A common design goal is to minimize the communication and
dependencies between subsystems.
● One way to achieve this goal is to introduce a Facade object that provides
a single simplified interface to the more general facilities of a subsystem.
Usage of Facade Design Pattern
● A Facade provide a simple default view of the subsystem that is good enough for
most clients. Only clients needing more customizability will need to look beyond
the facade.
● There are many dependencies between clients and the implementation classes of
an abstraction.
● A Facade to decouple the subsystem from clients and other subsystems, thereby
promoting subsystem independence and portability.
● Facade define an entry point to each subsystem level. If subsystem are dependent,
then you can simplify the dependencies between them by making them
communicate with each other solely through their facades.
UML of Facade Design Pattern
Java of Facade Pattern
Let’s start by defining an interface – BookGenre:
public interface BookGenre {
List<Book> getBookList();
}
Java of Facade Pattern
All classes representing different book categories will implement this interface:
public class Fiction implements BookGenre {
...
}
public class NonFiction implements BookGenre {
...
}
public class Technology implements BookGenre {
...
}
Java of Facade Pattern
We can let our client interact with all of the subsystem classes on its own to borrow a book.
But to simplify things out, let’s create a LibraryService as a facade which will expose these sort of functionalities:
public enum BookType { FICTION, NONFICTION, public void borrowBook(BookType type, String
TECHNOLOGY } name) {
public class LibraryService { List<Book> books;
private BookGenre fiction; switch(type) {
private BookGenre nonFiction; case FICTION: books =
private BookGenre technology; this.fiction.getBookList();
public LibraryService() { break;
this.fiction = new Fiction(); case NONFICTION: books =
this.nonFiction = new NonFiction(); this.nonFiction.getBookList();
this.technology = new Technology(); break;
} default: books =
this.technology.getBookList();
}
Book book =
BookService.findBookByName(books, name);
book.setAvailability(false);
}
...
}
Benefits of Facade Design Pattern
1. Simplifies complex subsystems: Facade provides a simple interface to a complex
subsystem, making it easier to use and understand.
2. Encapsulates subsystem functionality: It hides the complexity of the subsystem from
clients, reducing dependencies and coupling.
3. Promotes loose coupling: Facade decouples the client from the subsystem, allowing changes
to the subsystem without affecting the client.
4. Improves maintainability: Changes to the subsystem can be made without impacting the
client code, enhancing maintainability.
5. Enhances readability: Facade makes the code more readable by providing a clear and
concise interface to the subsystem.
References
1. https://www.programmergirl.com/java-facade-pattern/
2. https://www.tutorialspoint.com/design_pattern/facade_pattern.htm
3. https://www.geeksforgeeks.org/facade-design-pattern-introduction/
4. https://www.baeldung.com/java-facade-pattern
Thank You

You might also like