Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Someone explain facade to me

 
Mark Highwater
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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?
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks, I'm not really familiar with using patterns. It's still kind of daunting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic