Get up to 80 % extra points for free! More info:

Facade

The Facade design pattern is used to create a united interface for an entire logical group of classes representing a subsystem.

Motivation

We often work with several interfaces of different classes in our application. This can often be confusing, especially if these class interfaces are complex. If the classes are logically related, we can group them into a subsystem using Facade. This gives us a unified interface for the functionality provided by the subsystem.

Pattern

Facade is a fairly simple pattern that consists of a single class forming the facade. It's connected to other classes which it works with. However, from the outside, only the facade is visible (that's the reason why it's called this way), and it represents an interface for the entire subsystem. The whole complex structure of the classes is in the background.

The Facade design pattern - GOF - Structural Patterns

The number of classes we communicate with is reduced. The subsystem is easier to use and test. It's a mediator again and there is some similarity to the Adapter (Wrapper) pattern. However, we wrap multiple classes into one logical subsystem.

An example could be a facade for working with PC at the hardware level. It would group a class that allows the computer to sleep, restart, or shut down. Then, a class that would adjust the brightness of the monitor and another one, that would read processor and disk temperatures. The facade would unify all the methods into a single interface. It could contain only methods we selected for our purposes.

The advantage of the pattern is also resolving dependencies of individual components of the subsystem. If we pass an instance between them, it's done inside the facade.


 

All articles in this section
GOF - Structural Patterns
Article has been written for you by David Capka Hartinger
Avatar
User rating:
No one has rated this quite yet, be the first one!
The author is a programmer, who likes web technologies and being the lead/chief article writer at ICT.social. He shares his knowledge with the community and is always looking to improve. He believes that anyone can do what they set their mind to.
Unicorn university David learned IT at the Unicorn University - a prestigious college providing education on IT and economics.
Activities