Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

about the data model

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am working on displaying data into JTable, using the DataModel extends AbstractTableModel.
In order to get table data from db file, I going to create an instance of Data class in this DataModel class, and do all the data processing in there as well.
I am wondering it is a good idea or not.
please help,

lili
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ramesh kumaar:
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar


Hi Ramesh,
Can you give more details?
The way I have implemented is as follows: (not sure where design pattern can be applied !)
(a) CSR (Serice Representative) searches for a "Specialty"
(b) The Data class finds for all "Contractors" who match the specified specialty
(c) The Data class returns an array of objects - of type "DBResultSet" (I have given the definition below).
public class DBResultSet {
public int recno;
public String name;
public String location;
public String specialties;
public String size;
public String rate;
public String owner;
}
I added the following method in the Data class :
public DBResultSet[] find(String criteria) throws RecordNotFoundException {
...
}
(d) In the Swing application, read all the elements from the DBResultSet array and update the JTable model.
With the Beta almost over, I need to complete the assignment faster and start documentation !
Your advice on using design patterns in above code / functionality would be great !
Regards,
Dayanand.
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daya,
I think there is no need of having DataResultSet class as u have, because read() method of DBMain returns String[] which can be used strightaway in DefaultTableModel without
any change.
In my case DBMain.java is the interface which has all the methods that was given by sun. I have an implementation class which is named as DBMainImpl.java. Now to access the DB i have a class DBAccess.java which extends DBMainImpl.java and implements DBAccessInterface.java which has the following methods update, lock,unlock,search. The above interface is implemented by another interface named RemoteDBAccessInterface which acts as the remote interface in our project. Here i just instantiate DataAccess.java for remote clients.
Hope this may help.
Goodluck.
rameshkumar
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic