This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, I am designing the Model of my GUI. The Model (I called it FlightModel) uses a Facade class to get data from database server. I am wondering if the facade class should encapsulate Database classes (DBInfo,FieldInfo ...etc) from the FlightModel so that FlightModel has no knowledge of database at all. For example: define the method in facade as Object[][] searchFlight(String criteria); insted of DBInfo[] searchFlight(String criteria); I found if I do so, client can not specify the record number that he/she wants to lock in the bookFlight() method because the FlightModel does not have knowledge of database record number. Thus the bookFlight() might have to search the whole database to find the interested record to lock. Question:1) Should I expose the Database classes to FlightModel? or 2) Cache the Database data in Facade class ? Which one is a better choice ?
Originally posted by John Chien: I am wondering if the facade class should encapsulate Database classes (DBInfo,FieldInfo ...etc) ... I found if I do so, client can not specify the record number that he/she wants to lock in the bookFlight() method because the FlightModel does not have knowledge of database record number. Question:1) Should I expose the Database classes to FlightModel? or 2) Cache the Database data in Facade class ? Which one is a better choice ?
Short answer to #1: No. Long answer to #1: I can't remember the specifics of how I did it, but in general I created an implementation of TabelModel that I populated with plain Java data types. My GUI calls searchFlights on my controller, which calls a method on my facade, which returns a data structure without any mention of the db classes. My controller then places this information into the table model, and for record numbers I have a column in the TableModel that is not visible on the GUI. So basically, I am loading up my TableModel with my search results from the db. This may be the entire db depending on my search criteria.
My reason for not letting the TableModel know about the db classes was that I wanted to cleanly separate my layers. (Arrows indicate who can see who) [code]GUI (JFrame, JTabel, TableModel, etc) <--- Controller ---> Business (Facade) ---> Persistence[code] Don't let your GUI (TableModel) be tied to your persistence layer implementation.
John Chien
Ranch Hand
Joined: Feb 06, 2003
Posts: 105
posted
0
Thank you. This really help. You give me the hints of how I can have record number without knowing all the database classes. Yes, we should encapsulate those class using the facade class. Model should not know those classes. John Chien