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.