Black Friday Black Friday
Black Friday ultimate sale! Get up to 80 % extra free points! More information here

Facade

Software design Design patterns GOF Structural Patterns 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

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.


 

 

Article has been written for you by David Capka
Avatar
Do you like this article?
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 College The author learned IT at the Unicorn College - a prestigious college providing education on IT and economics.
Thumbnail
Previous article
Adapter (wrapper)
Thumbnail
All articles in this section
GOF - Structural Patterns
Thumbnail
Next article
Proxy
Activities (2)

 

 

Comments

To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

No one has commented yet - be the first!