A question on the Facade Pattern. Topic: Patterns
govind naroji, Sep 25, 2005 [replies:2]
Hi
I am using the Facade Pattern to create a web application in Struts.
I've got 3 sets of classes:
Database classes to fetch data from the database
Action Classes to display data on the web interface
Facade class which uses objects of the database classes and gives a set of functions to the Action Classes.
Should I create the objects of the Database classes directly in the Facade class or should I use an interface for the Database classes in the Facade class?
I want to do this so that if I want to use any object of the Database class directly in the Action Class(through the Facade Class that is...) then I dont have to access the Database Class Objects directly in the Action Class.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

 |
Re: A question on the Facade Pattern. Topic: Patterns
Christopher Koenigsberg PREMIUM, Sep 25, 2005
Your answer may depend on the kind of things you need to do.
You may want to make "business objects" in your "Facade", exposing business-related properties but not database-specific method. e.g. the Action might call for "find account with this acct number" etc. and the facade + the dao's decide, whether there's an existing one retrieved from the db, or a new one created and inserted into the db.
Also you may eventually want to go with something like Hibernate, where you would only write the business/Facade objects and then just build the db mapping via Hibernate and never call its components explicitly.
(though it seems that problems are much more difficult to debug, in a Hibernate-based application, at first glance)
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|
|
 |
Re: A question on the Facade Pattern. Topic: Patterns
Prabhath Soorasena, Dec 1, 2005
Note1: Dending on your application you may have large number of action classes. Rather having all Action classes call Facade class it's better to have functionaly group business deligation class in between Facade and Action class So then communication happens from Deligater to Facade and can have functional grouping on deligater and re-use from diffrent action classes.
Note2:
Depending on where you want to have your business logic you can get dtabase classes instance from the facade too. But it's good idea to seperate business logic there and handover those to seperate business classes and call those from the facade. So It gives the real benifit of facade patter (i.e functional grouping from fron-end to backend) Specialy if the deligater and facade operates remotely (like in two diffrent containers) you have to conside grouping business function call and reduce the cost of network call.
Thx
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|
|
|
|
 |
|