Home » Blog » Software Development » Software Design Patterns in PlantUML » Design Patterns with PlantUML: Facade Pattern

Design Patterns with PlantUML: Facade Pattern

This post gives a brief overview about the Facade Pattern. The post is part of a series about software design patterns and their UML representations with the help of PlantUML.

The article aims at providing a very short description of the general idea of the pattern in the first part. This also involves a descriptive UML diagram. Then, the second part provides the PlantUML code for the diagram so that these posts can also be used as a source of design patterns in PlantUML syntax.

What is the Facade Pattern?

According to Wikipedia, a facade can:

  • make a software library easier to use, understand, and test, since the facade has convenient methods for common tasks
  • make the library more readable, for the same reason
  • reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system
  • wrap a, subjectively, poorly-designed collection of APIs with a single well-designed API

Implementors often use the facade design pattern when a system is very complex or difficult to understand because the system has a large number of interdependent classes or because its source code is unavailable. This pattern hides the complexities of the larger system and provides a simpler interface to the client.

What problems can the Facade design pattern solve?

  • To make a complex subsystem easier to use, a simple interface should be provided for a set of interfaces in the subsystem.
  • The dependencies on a subsystem should be minimized.

Clients that access a complex subsystem directly refer to (depend on) many different objects having different interfaces (tight coupling), which makes the clients hard to implement, change, test, and reuse.

What solution does the Facade design pattern describe?

Define a Facade object that

  • implements a simple interface in terms of (by delegating to) the interfaces in the subsystem and
  • may perform additional functionality before/after forwarding a request.

This enables to work through a Facade object to minimize the dependencies on a subsystem.

UML Diagram

The following diagram shows the Facade Pattern in UML notation. It is based on the corresponding chapter in the book “Head First Design Patterns“:

PlantUML Syntax:
<p>@startuml<br />
class Client<br />
class Facade<br />
Client -> Facade</p>
<p>package “Subsystem Classes” <<rectangle>> {</p>
<p>note “More complex subsystem” as n1</p>
<p>Facade — “class 1”<br />
Facade — “class 2”</p>
<p>package “class 1” <<rectangle>> {<br />
}</p>
<p>package “class 2” <<rectangle>> {<br />
}</p>
<p>package “class 3” <<rectangle>> {<br />
}</p>
<p>package “class 4” <<rectangle>> {<br />
}</p>
<p>package “class 5” <<rectangle>> {<br />
}</p>
<p>package “class 6” <<rectangle>> {<br />
}</p>
<p>“class 1” — “class 2”<br />
“class 1” — “class 3”<br />
“class 2” — “class 4”<br />
“class 3” — “class 5”<br />
“class 3” — “class 6”<br />
“class 4” — “class 5”<br />
“class 4” — “class 6”<br />
}</p>
<p>note left of Client<br />
Happy client whose<br />
job just became<br />
easier because of<br />
the facade.<br />
end note</p>
<p>note right of Facade<br />
Unified interface<br />
that is easier to use.<br />
end note<br />
@enduml</p>

PlantUML Sources

PlantUML is a tool allowing users to create UML diagrams from a plain text language. Here are the PlantUML sources for the above software pattern:


@startuml
class Client
class Facade
Client -> Facade

package "Subsystem Classes" <<rectangle>> {

note "More complex subsystem" as n1

Facade -- "class 1"
Facade -- "class 2"

package "class 1" <<rectangle>> {
}

package "class 2" <<rectangle>> {
}

package "class 3" <<rectangle>> {
}

package "class 4" <<rectangle>> {
}

package "class 5" <<rectangle>> {
}

package "class 6" <<rectangle>> {
}

"class 1" -- "class 2"
"class 1" -- "class 3"
"class 2" -- "class 4"
"class 3" -- "class 5"
"class 3" -- "class 6"
"class 4" -- "class 5"
"class 4" -- "class 6"
}

note left of Client
Happy client whose
job just became
easier because of
the facade.
end note

note right of Facade
Unified interface
that is easier to use.
end note
@enduml

Other Design Patterns

In another article you find information about how to put together a single-side web application using PlantUML.

Proxy Pattern Design Pattern with PlantUML: Proxy Pattern - This post gives a brief overview about the Proxy Pattern. The post is part of a series about software design ... Read More
State Pattern Design Patterns with PlantUML: State Pattern - This post gives a brief overview about the State Pattern. The post is part of a series about software design ... Read More
Composite Pattern Design Patterns with PlantUML: Composite Pattern - This post gives a brief overview about the Composite Pattern. The post is part of a series about software design ... Read More
Iterator Pattern Design Patterns with PlantUML: Iterator Pattern - This post gives a brief overview about the Iterator Pattern. The post is part of a series about software design ... Read More
Template Pattern Design Patterns with PlantUML: Template Pattern - This post gives a brief overview about the Template Pattern. The post is part of a series about software design ... Read More
Facade Pattern Design Patterns with PlantUML: Facade Pattern - This post gives a brief overview about the Facade Pattern. The post is part of a series about software design ... Read More
Adapter Pattern Design Patterns with PlantUML: Adapter Pattern - This post gives a brief overview about the Adapter Pattern. The post is part of a series about software design ... Read More
Command Pattern Design Patterns with PlantUML: Command Pattern - This post gives a brief overview about the Command Pattern. The post is part of a series about software design ... Read More
Singleton Design Patterns with PlantUML: Singleton - This post gives a brief overview about the Singleton Pattern. The post is part of a series about software design ... Read More
Design Patterns with PlantUML: Abstract Factory Pattern - This post gives a brief overview about the Abstract Factory Pattern. The post is part of a series about software design ... Read More

Check Also

Proxy Pattern

Design Pattern with PlantUML: Proxy Pattern

This post gives a brief overview about the Proxy Pattern. The post is part of …

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

We use Cookies and similar technology to collect and analyse information about the users of this website. We use this information to enhance the content, advertising and other services available on the site. Please click ‘Accept cookies’ to consent to the use of this technology by petrockblock. You can manage your preferences at any time by visiting our Cookies Policy page.