0% found this document useful (0 votes)
55 views4 pages

Facade Design Pattern - Dev Genius

The facade design pattern hides the complexities of a system by providing a simplified interface. It involves creating a facade class that references complex subsystem classes and exposes their key functionality through simpler methods. For example, an AnimalMaker facade class is created that holds references to Dog, Cat, and Bird classes. It exposes species methods that call the corresponding methods in the concrete classes, hiding the instantiation of the real classes from the user. The facade pattern is useful for simplifying access to a complex system.

Uploaded by

dung pham anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views4 pages

Facade Design Pattern - Dev Genius

The facade design pattern hides the complexities of a system by providing a simplified interface. It involves creating a facade class that references complex subsystem classes and exposes their key functionality through simpler methods. For example, an AnimalMaker facade class is created that holds references to Dog, Cat, and Bird classes. It exposes species methods that call the corresponding methods in the concrete classes, hiding the instantiation of the real classes from the user. The facade pattern is useful for simplifying access to a complex system.

Uploaded by

dung pham anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

8/31/2021 Facade Design Pattern - Dev Genius

Facade Design Pattern


Daniel Liu Follow

Nov 11, 2020 · 2 min read

Overview
The main idea for the facade design is hiding the complexities of the application. The
user would use an interface/facade instead to access any methods.

Photo by Daniel von Appen on Unsplash

Implementation
Interface

https://blog.devgenius.io/facade-design-pattern-a07e2d0d585b 1/4
8/31/2021 Facade Design Pattern - Dev Genius

// Animal.java

public interface Animal {

void species();

Interface for concrete class.

Class Implementation

// Dog.java

public class Dog implements Animal {

@Override

public void species() {

System.out.println("Dog");

Interface implementations.

// Cat.java

public class Cat implements Animal {

@Override

public void species() {

System.out.println("Cat");

// Bird.java

public class Bird implements Animal {

@Override

public void species() {

System.out.println("Bird");

Facade

// AnimalMaker.java

public class AnimalMaker {

private Animal dog;

private Animal cat;

private Animal bird;

public AnimalMaker() {

dog = new Dog();

https://blog.devgenius.io/facade-design-pattern-a07e2d0d585b 2/4
8/31/2021 Facade Design Pattern - Dev Genius

cat = new Cat();

bird = new Bird();

public void dogSpecies(){

dog.species();

public void catSpecies(){

cat.species();

public void birdSpecies(){

bird.species();

Facade for user to access concrete class methods.

Demo

// Demo.java

public class Demo {

public static void main(String[] args) {

AnimalMaker animalMaker = new AnimalMaker();

animalMaker.dogSpecies();

animalMaker.catSpecies();

animalMaker.birdSpecies();

>> Dog

>> Cat

>> Bird

Instead of creating concrete classes you would call their methods through the facade.

Conclusion
You would probably use the facade pattern if you had a complex system. You would
want to hide the complexities and expose a simplified way for others to use.

Sign up for DevGenius Updates


By Dev Genius

Get the latest news and update from DevGenius publication Take a look.

https://blog.devgenius.io/facade-design-pattern-a07e2d0d585b 3/4
8/31/2021 Facade Design Pattern - Dev Genius

Get this newsletter

Facade Pattern Java Backend Development Programming Design Patterns

About Write Help Legal

Get the Medium app

https://blog.devgenius.io/facade-design-pattern-a07e2d0d585b 4/4

You might also like