• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Regarding Facade Pattern implementation

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have a doubt regarding pattern imlplementation.I am reading facade pattern and they had written JDBC is best example for facade pattern.
Connection is an interface and when i call a method say createStatement()
its creating the statement and returning a Statement Object.Statement itself is an interface.
I know here facade pattern is implemented but i am not able to understand how is it working.
Who implemented these interfaces.how will i see them.
i wanted to know how i can implement this.
Can somebody help me.
Regards
Kiran
[ September 03, 2003: Message edited by: Kiran Baratam ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually think of facade as a public object that provides a public face for a component or function, and a mess of private objects that do the real work. Facade hides all the complexity from the client, giving the client a simple set of public methods. This makes the client simpler, because it does not have knowledge of a lot of little implementation objects, and gives the component author freedom to change the implementation without telling the client, so long as all the contracts implied by the public methods are maintained.
JDBC does not jump out in my mind as doing this. And that might be because they've done it so well ... maybe there are zillions of detailed little implementation classes inside JDBC that I've never heard of. That might make Connection a successful facade after all!
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

... maybe there are zillions of detailed little implementation classes inside JDBC that I've never heard of. That might make Connection a successful facade after all!


In that case we have lot of facades in real life. How is facade defined in that case?
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:

In that case we have lot of facades in real life. How is facade defined in that case?


I'm a little confused with the above statement. All the little implementation classes are the ones masked by the facades. Am i missing something here
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what Pradeep meant was that almost any object you call a message on will delegate much of its work to many other little objects.
I think a good hint that an object is a facade is when
- it delegates to objects inside the same subsystem and gets used from outside the subsystem, and
- it doesn't contain much logic.
But I have to admit that it's something I am wondering about from time to time, too...
 
Kiran Baratam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody
Thansk for the replies.i am trying to implement patterns and currently i am reading the facade pattern.I understand the use of the facade and try to understand some implementation.I tried to figure out from DriverManagerClass which is using Driver interface, but did not find any way.I am not able to follow exactly what is heppening when i say
Statement stmt = connection.createStatement();
Can you please help me.
Regards
Kiran
[ September 03, 2003: Message edited by: Kiran Baratam ]
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Statement stmt = connection.createStatement();


The Statement gets created. Are you asking which pattern it is?
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose what distinguishes a facade from anything else that delegates work is that its main purpose is to simplify the public interface and deliberately hide the details. (Note that almost ALL the GoF patterns seek to simplify interfaces and reduce coupling, so that's a pretty generic objective.)
connection.createStatement() doesn't strike me as a facade because connection reveals to you that a statement exists rather than hiding details. And Connection has a some real functionality of its own so it does not exist primarily to simplify the API.
We have "create" in the name here, so look in the GoF category of creational patterns. This might be a FactoryMethod or a Builder or it might just be a simple convenience method that saves you writing a couple lines of code. Waddya think?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stan,
I dont think it is a Builder pattern but a factory pattern.
Create statement is a creational pattern so I dont think it can be a Facade which is structural.
[ September 04, 2003: Message edited by: Pradeep Bhat ]
[ September 05, 2003: Message edited by: Pradeep Bhat ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would actually say that it's AbstractFactory.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please explain?

Originally posted by Ilja Preuss:
I would actually say that it's AbstractFactory.

 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AbstractFactory deals with creation of families of related objects supporting the same interface. I think factory pattern is the best fit here.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And of course since there are no pattern police enforcing rules (and in fact no rules!) an object can participate in several patterns at once. Connection might be a factory for statements, a facade hiding some database details, and a first-order domain object all at once. Which might lead you to some opinions about certain qualities of the design.
[ September 05, 2003: Message edited by: Stan James ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jayadev Pulaparty:
AbstractFactory deals with creation of families of related objects supporting the same interface. I think factory pattern is the best fit here.


There is no Factory pattern - at least not in the GoF book.
There is a Factory Method pattern, where a factory method is declared and used in a class, but implemented by subclasses.
And there is the Abstract Factory pattern, where there is an interface defined for the factory method and actual implementations handed around (and used, of course) by other objects.
At least, that's my current understanding - and from that, the latter seems to be a better fit for connection.createStatement().
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm really not sure if Factory is a GoF pattern. I don't think so. I came across this in Larman's book - Applying UML and patterns. What it says is that if there is some creational logic involved for an object, the class that is supposed to create the object should not be concerned about it. It makes it less cohesive w.r.t its responsibilities. It can delegate the job to a factory class that takes care of it.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kiran Baratam:
I tried to figure out from DriverManagerClass which is using Driver interface, but did not find any way.I am not able to follow exactly what is heppening when i say
Statement stmt = connection.createStatement();
[ September 03, 2003: Message edited by: Kiran Baratam ]


Hi Kiran,
I think you may be approaching this from the wrong side. The idea of the facade pattern is that you have an obect (the "facade" = 'connection'), and within the facade you have a multitude of classes which have their own methods. The facade will hide these classes and only expose the appropriate methods to you.
When you look at this code you do not see the inner workings of the facade pattern - only the end implementation. For a better understanding of how to use the facade pattern visit this link javaworld facade pattern
Regards,
Fintan
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic