• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Facade Design Pattern

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can someone explain to me how the facade design pattern work?

Thanks in advance
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raghav singh wrote:Can someone explain to me how the facade design pattern work?


Have you read the Wikipedia page? It's pretty good.

Or was there something specific about the pattern that you wanted clarified?

Winston
 
raghav singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:
was there something specific about the pattern that you wanted clarified?
Winston



Yes need to confirm if i am understanding the facade pattern with someone.

Ok... here is what i understand so far

What i understand is that a facade class uses only a part of the system or use it in a particular way

For example a system have the following class:
Class A has method1 and method2
Class B has method3 and method4

If i want to use only part of it... i will use a facade class like this

class facade will have for example
1.method2 of class A and
2.method41 (which uses a method 4 of class B and method 1 of class A)

So am i getting it right?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raghav singh wrote:So am i getting it right?


Maybe. But the main reason is to understand WHY you use it; and that's explained pretty well in the page I linked.

I also wonder if you may not be worrying about this too soon. Patterns are generally something that you get into once you really know the basics - which took me about a year. If you start worrying about them before you're ready, they can just be a distraction, because you're worrying more about the "pattern" than you are about getting your object working and writing it well.

The general idea of patterns is that they should galvanize something that you've already thought about yourself, so that you go "Aaah, so THAT'S what it's called!...". They shouldn't be some name that you simply learn about by rote.

Please feel free to correct me if I'm wrong.

Winston
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My two cents:

I like to call the Facade pattern the Adapter pattern, because I think it better described what it does.

You can use it to connect to APIs that have different method names. Say you have an API you control (it's in your project) and one you can't (it a third party). You can create an adapter to your API to fit the third party API.

Sometimes Adapters are used to simplify a complex or poorly written API.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Sometimes Adapters are used to simplify a complex or poorly written API.


Actually, that's what I always thought Facades were used for - and there, I suspect, is the distinction.

An Adapter can be used to convert (within reason) any behaviour to any other. A Facade is simply a specialisation of an Adapter.

But your explanation is excellent.

Winston
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I like to call the Facade pattern the Adapter pattern, because I think it better described what it does.


This is approaching the slippery slope of what Martin Fowler calls semantic diffusion. Patterns and their names help to facilitate communication. When someone says "Facade," there's a very specific context associated with it and it is different from the context that would be associated with "Adapter". So, instead of facilitating the conversation by using the pattern name, you may very well end up confusing people when you say "Adapter" but really mean "Facade".

The difference between Facade and Adapter lies mainly in the intent.

Adapter - if you travel from the US to Asia or Europe, chances are you'll need an adapter to be able to use your US phone charger with Asian and European wall sockets. That's because your US plug will not fit in many foreign standard sockets. Adapters allow you to convert from one type of interface to another. In software, adapters are useful when you want to keep using one type of interface (your US plug) but behind the scenes deal with a different type of interface (the European socket).

Facade - on the other hand, the intent behind a facade is simplification. You want to hide certain details or complexities so that the client has a better, often simpler API. Real-world example is the steering wheel on your car. We all know to turn the wheel in the direction that you want the car to go. The complexities of the rack and pinion or recirculating ball or power assisted mechanism is hidden from you. The steering wheel is the facade that makes your life as a driver easier.

I like this article: http://www.agileevidence.com/2009/04/differentiating-between-adapter-and.html


 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic