Evgenii Legotckoi
Evgenii LegotckoiSept. 27, 2018, 5:11 a.m.

Structural Design Patterns - Facade

Goals

  • Provide a unified interface for a set of interfaces in a subsystem. A facade defines a higher-level interface that makes the subsystem easier to use.
  • Wrap a complex subsystem with a simpler interface.

Problems

The client access segment requires a simplified interface to access the common functionality of a complex subsystem.


Discussion

A facade encapsulates a complex subsystem within a single interface. This reduces the learning curve needed to successfully use the subsystem. It also helps decouple the subsystem from potentially many clients. On the other hand, if the Facade is the only access point for a subsystem, this will limit the power and flexibility that "advanced users" may want.

The Facade object should be a fairly simple intermediary. It should not become an omniscient oracle or a "divine" entity.

Structure

The façade takes "an enigma wrapped in an enigma shrouded in mystery" and adds a shell that tames an amorphous and incomprehensible mass of software to provide a simple and understandable client interface.

SubsystemOne and SubsystemThree do not interact with SubsystemTwo internals. They use a SubsystemTwoWrapper "facade" (i.e. a higher level abstraction).

Example

A facade defines a higher-level unified interface to a subsystem that makes it easier to use. Consumers face a facade when ordering from a catalog. A consumer calls one number and talks to a customer service representative. The customer service representative acts as a front, providing an interface to the order fulfillment, billing, and shipping departments.

Control List

  1. Define a simpler unified interface for a subsystem or component.
  2. Create a 'wrapper' class that encapsulates the subsystem.
  3. Facade/wrapper eliminates the complexity and interaction with the component by delegating the appropriate methods.
  4. The client uses (attached to) only the facade.
  5. Consider whether the facade will add additional value and functionality.

Rules of thumb

  • Facade defines a new interface, while Adapter uses the old interface. Remember that an adapter supports two existing interfaces, not defines a completely new one.
  • While Flyweight shows how to make many small objects, Facade shows how to make one object representing an entire subsystem.
  • A mediator is similar to a Facade in that it abstracts the functionality of existing classes. The mediator abstracts/centralizes arbitrary relationships between peer objects. In contrast, Facade defines a simpler interface for a subsystem, it does not add new functionality, and it is not known to subsystems.
  • Abstract Factory can be used as an alternative to Facade to hide platform-specific classes.
  • Facade objects are often singletons because only one Facade object is required.
  • Adapter and facade - both wrappers; but they are different kinds of wrappers. The purpose of a Facade is to create a simpler interface, and the purpose of an adapter is to develop an existing interface. While a Facade typically wraps multiple objects, an Adapter wraps a single object; The facade could have an interface complex with a single complex object, and the adapter could wrap multiple legacy objects.
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
e
  • ehot
  • March 31, 2024, 10:29 p.m.

C++ - Тест 003. Условия и циклы

  • Result:78points,
  • Rating points2
B

C++ - Test 002. Constants

  • Result:16points,
  • Rating points-10
B

C++ - Test 001. The first program and data types

  • Result:46points,
  • Rating points-6
Last comments
k
kmssrFeb. 9, 2024, 3:43 a.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 7:30 p.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 5:38 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 19, 2023, 6:01 a.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
a
a_vlasovApril 14, 2024, 2:41 p.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 14, 2024, 10:35 a.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 12:47 p.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…
AC
Alexandru CodreanuJan. 19, 2024, 8:57 p.m.
QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…

Follow us in social networks