-
What facade design pattern is?
This is an obvious question as it was in my mind when i first time heard this word. And if it is so important in our development process so why it remained out of screen yet? In fact facade is in our practice but we forgot where and how are we using it in our daily basis coding problems.
If we check its meaning so it is “The face or front of a building”, think on it with a little concentration that “front of a building” not inside of building or any other details. The whole story lies in it.
Few teachers call it “Illusion” as well. Because what are we seeing; does not exist and what does exist is hidden from us.
Ok, i shorten it and let recall our memory of OOP where we feel much convenience when we work on Object Oriented Modeling. Facade in fact is design pattern which provide a simple interface to a complex sub-system. We use it when we have to re-arrange a complex model into façade pattern which will obviously be an illusion not reality but will make it look simpler. In fact it provides a unified interface to a set of interfaces in a subsystem.
-
How will facade design pattern reduce complexity in website development?
To answer this question if i take example of our newspaper website in which a large no. of records is a normal routine. Every news has a large no. of viewers and readers. Few database fields are being updated periodically and few perpetually.
e.g.
- Most read news
- Most commented news
- Most searched news etc.
Now think for a moment that if one of your website module want to show this information like a widget and you want it like a magic. Where following things can be involved.
- News title, description, images, related video etc.
- News author information and source etc.
- News response, comments, critics and prospects data etc.
All of this obviously will be coded by you but will you like code a complete controller for it?
NO
And you will not like to code a function for it even you won’t like to put all queries as a business logic in a model function. Then how it should be?
Have a look on this diagram:
Your function call will work outside facade subsystem and you will be facilitated by facade with the convenience as your call interacting inside that complex subsystem without interacting directly. That is in fact illusion that you just called facade class and everything is done magically which is not in real.
-
Understanding Facade with respect to object oriented programming:
Just having all those methods which you will required to develop that widget, have a look on this car object and its functions. Same like this you will define and code all those complex functions and name that class as a “newsUpdates” or something which will make sense of latest, most read or viewed news etc.
-
How to draw and understand facade design pattern?
You can try it with ArgoUML. As i did it for my assignment of software engineering.
-
How will facade provide a unified interface to a set of interfaces in a subsystem?
Facade will get instructions from client software and will interact inside subsystem to get the desired results. It depends upon our style of coding that how we do it, either we subdivide our problem in further more classes or just one class will be enough for us? But keep remember that either you create more than one class, still you do not need to bother about interacting with those all. You will still just call facade class and that’s it. Facade will call all relevant or desired methods in its constructor and will derive results for you.
-
How and why client classes and subsystem classes are different?
The answer of how is simple that while we are interacting with our ATM machine so we just press a button and ultimate desire is to get money from it. And to answer why, if we suppose our ATM machine and its program as a facade class so it will further work with complex methods inside it. So we are client and ATM machine is subsystem class(es). That is why the client classes are different from subsystem classes because client classes don’t have detailed instructions but subsystem classes do have.
-
Can we create more than one subsystem classes?
Obviously yes because it depends upon our requirements and the objects for which are we coding? If they are different and their actions and attributes are different so they will be independent or whatever relationship among or between those classes.
-
An example of facade design pattern from my assignment:
Given Object Model of a mathematics library was not in arranged form, which could be used by any (client) software, to perform mathematical calculations. The client software could call the functionality through class objects. We were required to re-arrange (re-design) this object model by implementing the Façade Pattern (i.e. to implement façade pattern on this model). Have a look on it and give me feedback that does it making the concept clear?
I used ArgoUML, i am not so good in it but i tried this one and i feel comfortable with it.
Wait for my next article on design patterns in which i will give an example with the help of OOP in PHP.