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>
<p>@startuml<br />
class Client<br />
class Facade<br />
Client -> Facade</p>
<p>package “Subsystem Classes” <> {</p>
<p>note “More complex subsystem” as n1</p>
<p>Facade — “class 1”<br />
Facade — “class 2”</p>
<p>package “class 1” <> {<br />
<p>package “class 2” <> {<br />
<p>package “class 3” <> {<br />
<p>package “class 4” <> {<br />
<p>package “class 5” <> {<br />
<p>package “class 6” <> {<br />
<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>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 />

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:

class Client
class Facade
Client -&amp;amp;gt; Facade

package &amp;quot;Subsystem Classes&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

note &amp;quot;More complex subsystem&amp;quot; as n1

Facade -- &amp;quot;class 1&amp;quot;
Facade -- &amp;quot;class 2&amp;quot;

package &amp;quot;class 1&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

package &amp;quot;class 2&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

package &amp;quot;class 3&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

package &amp;quot;class 4&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

package &amp;quot;class 5&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

package &amp;quot;class 6&amp;quot; &amp;amp;lt;&amp;amp;lt;rectangle&amp;amp;gt;&amp;amp;gt; {

&amp;quot;class 1&amp;quot; -- &amp;quot;class 2&amp;quot;
&amp;quot;class 1&amp;quot; -- &amp;quot;class 3&amp;quot;
&amp;quot;class 2&amp;quot; -- &amp;quot;class 4&amp;quot;
&amp;quot;class 3&amp;quot; -- &amp;quot;class 5&amp;quot;
&amp;quot;class 3&amp;quot; -- &amp;quot;class 6&amp;quot;
&amp;quot;class 4&amp;quot; -- &amp;quot;class 5&amp;quot;
&amp;quot;class 4&amp;quot; -- &amp;quot;class 6&amp;quot;

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

Other Design Patterns

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