• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can model know about database classes?

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic