• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

NX: Someone explain facade to me

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've seen several people suggest using a facade for the Data class. Can someone explain exactly?
So the DataFacade class will return a Data object for local mode and returns a reference to the existing Data object for network mode? Do I have this right?
 
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Nope.
The idea of Facade pattern is that it allows you to simplify the complexity by providing a simplified interface to the subsystems (to the client).
It doesn't return Data object. It has its own methods, which can be different from Data class: they throw other exceptions, they provide other functionality, they have other arguments or return values.
DB ´┐Żnterca provides low-level data access method, which is horable for the client application. Facade Pattern allows to define a high-level data access methods.
Example:
DB interface:
String[] readRecord(int recNo) throws RecordNotFoundException, MyIOUncheckedException;
FacadeInterface:
Record readRecord(int recNo) throws RecordNotFoundException, MyIOCheckedException;
Vlad
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well a Facade can sometiems be called a Wrapper pattern. Basically you hide the detail implementation of a class or system from a client. The client therefore only needs to call on the Facade class with easy to understand method names, like "book" or "search". All the complex searching and booking logic is hidden to the client. The Facade knows the complexity and calls the appropriate classes to actually perform the task.
In the case of the SCJD Assignment, the Facade class will have a reference to a DataAccess interface instance. It could be the remote or the local implementation of this interface. The Facade will call the appropriate methods to do a booking or a search. Because of this the Client only has to have one reference and that is to the Facade, and the client will never know or care to know whether it is in local or remote mode.
Taken from the Gof book

Intent: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use


So the Facade provides a way to have a single class to represent a complex subsytem of many classes. So that a client only deals with one class.
Hope that helps.
Mark
 
Mark Highwater
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'm not really familiar with using patterns. It's still kind of daunting.
 
grapes are vegan food pellets. Eat this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic