• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing good Java classes in the business tier  RSS feed

 
Rida Abrahams
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I'm busy writing a java application in J2SE, using MySQL as my database. I'm having trouble designing good classes to represent the way my business objects interact with each other. Can anyone recommend a good book on designing good business classes and the way they interact with each other. The book should preferrably have good examples. Most java books I've read on J2SE don't have good examples on how to create real world classes like a Customer class, Order class, Product class. I'm looking for a practical book that shows you how to write a java application in J2SE that use business objects that use SQL queries to manipulate the data in the application. Please help.
Thanks
Fathima Khan
SCJP 1.4.
 
brad balmer
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that this question asked to 5 different people would give you 5 different answers. Also, "I" have not seen any books specifically related to this subject.
From my own experiences though, writing a class (JavaBean) that corresponds to a single row in a table has worked out great for me.
For example:
Let's say you have a customer table with 4 columns:
id integer,
name varchar(150),
address varchar(150),
attribute char(2)
I would create a JavaBean:
private int id = 0;
private String name = null;
private String address = null;
private String attribute = null;
with appropriate getters and setters (following JavaBean specs)
public void setId(int id) { this.id = id; }
public int getId() {return this.id;}
public void setName(String name) {this.name = name;}
public String getName() {return this.name;}
etc.
And then your method do some DB work on this:
public void populate(int id) {
//Call db method to populate this instance based on the id
}
public void delete(int id) {
}
public void create(customer cust) {
}
etc.
If you need to do more manipulating of this class you could create another 'business object' class CustomerBO which instantiates the individual customer beans and does more with them.
I hope this hasn't confused you and has helped some.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!