• 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 pattern

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

What is the advantages of using the facade pattern with database access? What would have happened, if I didn't use it here and Are there any other alternatives?

Here is the code snippet:


Thanks,
Vlada
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mainly the facade serves as a level of indirection. If you change the db stuff, your other code doesn't change.

This is more of an OO question than database one, so I'm moving it to our OO/Design forum.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a rule I would try and avoid using static methods or Singletons with such a facade class, though.

One of the main benefits (for me) of a facade class is that it allows me to easily "swap out" a whole chunk of the system (in this case the real database implementation) for a "mock" version during unit testing. That way I can easily and quickly check hundreds of different paths through the business logic without incurring the hassle of setting-up/clearing-down data or the time it takes to connect and disconnect to a real database.

I'd pass in a DatabaseFacade object to the Control contructor (or at the very least fetch it from JNDI or some other pre-configured repository).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic