aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Facade help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Facade help!" Watch "Facade help!" New topic
Author

Facade help!

Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
hi,
I'm now desinging the client and I use the mvc design pattern.
1>Could I use the Facade Pattern and mvc at the same time?
2>What is the main purpose of the Facade?
3>What method should be put in Facade?
I'm a new learner of Facade,could you help me?
Thanks,
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
Originally posted by Ray Cheeny:

I'm now desinging the client and I use the mvc design pattern.
1>Could I use the Facade Pattern and mvc at the same time?

Yes.
Originally posted by Ray Cheeny:
2>What is the main purpose of the Facade?

To create a simpler interface that hides the more complicated code from the common developers of your system.
Originally posted by Ray Cheeny:
3>What method should be put in Facade?

Things like bookFlight(...) so that, like I said above, the common developer does not have to lock records, modify the db, unlock records, etc... instead they can just call a book method and not worry about the complex stuff.


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
hi Nate,
Thanks for reply.
1>Do you mean the facade is a interface which have the common untility methods?Also I should create a class like FacadeImp.class to implement it,right?
2>Should I put the method which will do the transform between local and network?Where did you put it?
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
Originally posted by Ray Cheeny:
hi Nate,
Thanks for reply.
1>Do you mean the facade is a interface which have the common untility methods?Also I should create a class like FacadeImp.class to implement it,right?
2>Should I put the method which will do the transform between local and network?Where did you put it?

1) No, it is just a class... I used interface just to mean that it was a way to get to common methods
2) I had a connection factory that would return a LocalData or RemoteData (in the form of a DataInterface) based on command line input from the user at startup... I put mine in the client.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Hi Ray.
The main idea of a Facade pattern is to hide a lot of methods, into specific methods that the outside understands.
For instance, when you buy stock, you call your Broker, "The Facade" and call his buyMeStock method where you tell him which stock and how many shares to buy. But do you know what the Broker does after that phone call? Probably not, he might have to access your account, see if you have enough money, call the runner on the Stock Market Floor, have him make a buy, then the runner calls back and tells the Broker that he bought the stock, give him the price. Then the Broker has to make sure that accounting knows that you bought stock. And if you are a Rich investor that is buying lots of Sotkc, there is Government papers that need to be filled out, etc.
I think you get the idea.
The Broker is your Facade because all you have to do is tell the Broker to buy you stock, you never need to know what happens underneath that layer, and all the objects that the Broker needs to call to accomplish the complete task of Buying.
This is another way to decouple classes and abstract things out, so that changes can be made by just swapping out the underneath layer without affecting clients.
Hope that helps
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi,
Thanks.IF you use the facade design pattern,do you
still use MVC?I just don't how to combine facade
with mvc?
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
Originally posted by Ray Cheeny:
Hi,
Thanks.IF you use the facade design pattern,do you
still use MVC?I just don't how to combine facade
with mvc?

Sure... that is what I did... when the view tells the controller that a booking event or a search event has occured the controller can ask the facade to search(...) or bookFlight(...).... this makes the controller very easy to read and gets your facade pattern in there along with the mvc
George Lawniczak
Greenhorn

Joined: Aug 12, 2002
Posts: 27
I liken the facade in this case to a session bean. What I mean is that it encapsulates the workflow issues, so that any client is relieved of having to know this. I could also conceivably service multiple types of clients, it could be a Swing app as is the case for this project. Or it could even be called from a servlet. So basically, the facade should have no knowledge about the client that is calling its methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facade help!