Facade Design Pattern is one of the simplest design patterns that is used frequently in software design. As per Wikipedia, the word ‘Facade’ is derived from the building architecture term Facade which is one exterior side of a building. This is the “interface” to the building. In the same way, a Facade is an interface to a larger body of code. More details are available at this Wikipedia link.
Please check out my new video on the Facade Design Pattern.
This video provides a simple example from real life where an individual acts like a “Facade”. A surveyor has a questionnaire that needs the following information:
1. Age Range of the person filling the survey
2. Income Range of the person filling the survey
3. Name of their favorite cafe in the city.
Lets assume that the person who wants to conduct this survey needs to visit an office building and collect this information from all the employees working in that building. One way to do this would be to speak to each employee and collect this data. This is, of course, assuming they will allow the survey person to speak to each employee. Another option is to speak to the location supervisor and hand over these survey to that person. The supervisor would talk to each employee, collect this information and hand over the responses on a stack of paper or electronic document to the survey person. This greatly simplifies the interaction between the survey person and the employees in that building. And in this case, the supervisor is the ‘facade’ to the employees in the building. Please note that the total number of interactions for data collection does not change but the interface between the survey person and the the employees is certainly simplified. This is application of the “Facade” pattern in terms of human interaction.
If we extend this model to software design, we could consider this scenario as an example. We have a class library called GeographicalServicesLibrary. The purpose of this library is to provide the distance between two addresses. This class library consists of the following classes:
a. Address Validator – This class exposes a solitary method that takes an address as a string parameter and returns a properly formatted address (format defined by postal service) to the caller. If the address is invalid, the returned string would contain an error code.
b. Geocode Helper – This class exposes a method that takes a properly formatted address and returns a Point object that contains the coordinates of that address (latitude and longitude).
c. Distance Calculator – This class provides a method that calculates the distance between two Point objects.
In order to calculate the distance between two addresses, the client object has to perform the following calls to this class library:
i. Call the Address Validator method and validate the first address.
ii. Call the Address Validator method and validate the second address.
iii. Call the Geocode Helper method and get the coordinates of the first address.
iv. Call the Geocode Helper method and get the coordinates of the second address.
v. Call Distance Calculator method and pass the coordinates of the two addresses and get the distance between the two coordinates.
This is shown in the c# code below:
//validate the first address String ValidatedAddress1 = AddressValidatorObject.ValidateAddress(Address1); //validate the second address String ValidatedAddress2 = AddressValidatorObject.ValidateAddress(Address2); //get the coordinates of the first address Point p1 = GeocodeHelperObject.GetGeoCode(ValidatedAddress1); //get the coordinates of the second address Point p2 = GeocodeHelperObject.GetGeoCode(ValidatedAddress2); //calculate the distance between the two addresses Double Distance = DistanceCalculatorObject.GetDistance(p1, p2); |
The total number of interactions between the client object and the class library members can be significantly reduced by introducing a “facade” object called the Geographical Service Facade. This class could expose a method that would take the two addresses as input parameters and return the distance between the two addresses. This facade object could interact with the members of this class library to get the desired output (distance between two addresses). The Facade class reduces the dependencies between the client and the class library members because only one class (the Facade) has dependencies on the class library. This is specially important if the class library is a third party library that may get replaced later. If a replacement is needed, only the one call in the Facade needs to change.
This is shown in the c# code below:
//calculate the distance between two addresses Double Distance = GeographicalServicesFacadeObject.CalculateDistance(Address1, Address2) |
Also, you could argue that the class library was poorly designed. If the goal of the class Library is the return the distance between two addresses, all it had to do was to keep expose this functionality perhaps as a Facade object. And the library could hide the three classes – Address Validator, Geocode Helper and Distance Calculator. This brings forward another advantage of the Facade Pattern that it simplifies interactions with a poorly designed library. In general, Facade Pattern makes a library or any collection of components easy to use and test. This is because the interface to the components is greatly simplified due to the introduction of the Facade object. Please note that Facade does not necessarily has to hide a large collection of components or a class library. It could just be introduced to simply interactions among any collection of objects.
Thanks for visiting this site and reading this post. Hope you liked the explanation. I’d love to get your feedback on this post and also your experience with the Facade Design Pattern.
It’s very simple to find out any matter on web as compared to textbooks, as I found
this article at this web page.
I am truly thankful to the holder of this site who has shared
this wonderful article at here.
I know this if off topic but I’m looking into starting
my own blog and was wondering what all is needed
to get set up? I’m assuming having a blog like yours would cost a
pretty penny? I’m not very web smart so
I’m not 100% positive. Any suggestions or advice would be greatly appreciated.
Cheers
Setting up a WordPress Blog like mine does not cost much. And you don’t need to be a web developer to get a site like this up and running. You need to first register you domain and then start a WordPress Blog. All you need is good content. You can get all this done for less than $20 USD. If you perform an internet search on ‘How to set up a WordPress Blog’, you will find many useful resources. I recommend this youtube link.
https://www.youtube.com/watch?v=5ZrLIhP2zy0
Do you mind if I quote a few of your articles as long as I provide credit and
sources back to your weblog? My blog site is
in the very same area of interest as yours and my visitors would truly
benefit from some of the information you provide here. Please let me know if this alright with
you. Appreciate it!
Sure. Please go ahead and share my site links.
Trust the financial Bot to become rich.
Link – – https://tinyurl.com/y7t5j7yc
Интересная новость
_________________
казино с бонусом 200 рублей
casino x отзывы россия
casino x зеркало официальный сайт казино
schweizer franken stabil wertpapier portfolio stellar mac data recovery i sent litecoin to a bitcoin address wertpapier portfolio neo é um programa intel börse wertpapier portfolio stellar equipment shop
Hello, I enjoy reading all of your article post.
I wanted to write a little comment to support you. https://www.minientrepotssaintcalixte.ca
Every your dollar can turn into $100 after you lunch this Robot.
Link – https://tinyurl.com/y7t5j7yc
One dollar is nothing, but it can grow into $100 here.
Link – – https://tinyurl.com/y7t5j7yc
http://printkor.ru
Kira2 game y keluar kapan bos,, udah ngga sabar nih pengin main di
mboplay,,
неотразимый веб ресурс
Библиотека порно рассказов для взрослых
Если вам нужно заказать винтовой конвейер в Самаре, то советую воспользоваться услугами компании «Проект плюс». Их сайт находится по адресу всеконвейеры.рф. Работают по всей России. Цены демократичные, сроки изготовления очень быстрые, качество хорошее.
Купить винтовой конвейер в Самаре можно заказав на сайте всеконвейеры.рф
вход на сайт azino777
azino777 официальный сайт с бонусом
Learn how to make hundreds of backs each day.
Link – https://tinyurl.com/y7t5j7yc
казино фараон онлайн на деньги
почему не заходит в казино фараон
мобильное приложение казино pin up
пин ап играть казино
play fortuna casino мобильная версия
плей фортуна на деньги
vulkan slots мобильная версия
вулкан слотс адрес
perdere peso velocemente
Dr. Brown’s Baby First Year Transition Options+ Baby Bottles Gift Set, Pink
Newborn Baby Boys Girls Sleeveless Romper Jumpsuit Bodysuit Outfits Set Clothes
как выиграть в гранд казино
https://grand-kazino-online.host/games гранд казино рулетка
Online earnings are the easiest way for financial independence.
Link – https://tinyurl.com/y7t5j7yc
The financial Robot is your future wealth and independence.
Link – – https://tinyurl.com/y7t5j7yc
https://lustra40.ru/svetilniki/svetodiodnye-led/
Светильники
Even a child knows how to make money. This robot is what you need!
Link – https://tinyurl.com/y7t5j7yc
Случаи : Препараты https://big-penis.com.ru/nexus-main.html -Феромон двойной концентрации Как стать сексуально привлекательным?
Thousands of bucks are guaranteed if you use this robot.
Link – https://tinyurl.com/y7t5j7yc
SUPERHOMUSE Portable Pet In-car Booster Car Seat Dog Mesh Hanging Breathable Water Double Layers Outdoor Travel Car Mat for Small Dogs Cats
Bedtime Originals Jungle Fun Musical Baby Crib Mobile – Gray, Animals, Jungle
Hello there! order lasix overnight delivery lasix drug price
маков и партнеры подготовка к егэ – подготовка к огэ 2020, подготовка к егэ по литературе
лечение алкоголизма – кодироваться от алкоголизма, снять ломку
see here now empire market link
Have no money? It’s easy to earn them online here.
Link – https://tinyurl.com/y7t5j7yc
moved here empire market url
# 1 financial expert in the net! Check out the new Robot.
Link – – https://tinyurl.com/y7t5j7yc
купоны на гугл адвордс – купоны гугл адвордс 2020 купить, промокод яндекс директ 3000 руб
use this link гидра
Отдых на черном азовском море
казино икс casino x зеркало
казино х бездепозитный бонус рублей
Половая контакт Среди мужчин бытует мнение, что такой преобразованный член произведет на женщину сильное впечатление и доставит ей большее наслаждение – Около темы члена.. https://sexpreparat.ru/about/11 -Толстый или длинный Секреты фаллоса: почему пенис имеет такую форму?
Lambs & Ivy Disney Baby Magical Mickey Mouse Changing Pad Cover – Gray
WOWmazing Kit 3-Piece Set | Incl. Big Bubble Wand, Giant Bubble Concentrate and Tips and Trick Booklet | Outdoor Toy for Kids, B
влагалище “Как увеличить размер мужского полового члена” : uvelichenie-chlena https://big-penis.com.ru/15.html – Метод Доения Увеличение пениса с методом “Доения”,увеличение члена
Крымск на карте
reduslim