Hello
I wonder if anyone can advise me here; I have an application which has classes like this:
Code:
public class Order implements Serializable {
private int orderNo;
private int customerNo;
private date orderDate;
public int getOrderNo () {
return orderNo;
}
public int getCustomerNo () {
return customerNo;
}
public date getOrderDate () {
return orderDate;
}
// And so on with set methods.
}
public class OrderLine implements Serializable {
private int orderNo;
private int lineNo;
private int qty;
private int prodID;
// Get and set methods for each of the above.
public int getOrderNo () {
return orderNo;
}
public int getLineNo () {
return lineNo;
}
public int getQty () {
return qty;
}
public int prodID () {
return prodID;
}
// And so on with set methods.
}
This translates directly into relational table:
Order: orderno, customerNo, orderDate OrderLine: orderno, lineNo, qty, prodID
So each class directly translates into a database table with get and set pairs for each attribute.
Now what I want to know is, if in an Java web application, should the classes be as they are above or more like this where the gets return objects:
Code:
public class Order implements Serializable {
private int orderNo;
private Customer;
private date orderDate;
private ArrayList<OrderLine>lineItems;
public int getOrderNo () {
return orderNo;
}
public Customer getCustomer () {
return Customer;
}
public date getOrderDate () {
return orderDate;
}
public ArrayList<OrderLine> getOrderLines () {
return lineItems;
}
public OrderLine[] getOrderLines () {
return lineItems;
}
// And so on with set methods.
}
public class OrderLine implements Serializable {
private int orderNo;
private int lineNo;
private int qty;
private Product;
// Get and set methods for each of the above.
public int getOrderNo () {
return orderNo;
}
public int getLineNo () {
return lineNo;
}
public int getQty () {
return qty;
}
public int getProduct () {
return Product;
}
}
Which is the better approach? Or does it really matter which approach is taken as long as the classes processing the data do so correctly and the system operates efficiently?
Thanks
Mr Morgan