Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facade help!

 
Ray Cheeny
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ray Cheeny
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ray Cheeny
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic