【发布时间】:2013-05-03 09:51:07
【问题描述】:
我有两张桌子:tblCustomer、tblProduct:
tblCustomer:
Id: Integer, auto-increament
Name: Varchar(30)
....
tblProduct
Id: Integer, auto-increament
Name: Varchar(50)
customerId: Integer
....
还有两个类:Customer、Product:
public class Product
{
private int id;
private int name;
/* Other stuffs */
}
public class Customer
{
private int id;
private String name;
private String phoneNumber;
/* get-set and others stuffs */
public static boolean add(Customer cus) {
/* This is for insert a customer to tblCustomer */
}
public boolean addProduct(Product pd) {
/* This is for insert a product to tblProduct with current customer Id */
}
}
客户注册账号时,调用:
Customer cus = new Customer(/* ... */);
Customer.add(cus);
当客户购买产品时:
Product pd = new Product(/* ... */);
currentCustomer.addProduct(pd);
但是我的老师说它在 OOAD(甚至 OOP)中不正确,因为 Customer.addProduct 是在 tblProduct 表上运行的,对吗?这个案子有什么好的设计?
** 更新:**
产品还没有预定义,当客户购买产品时,商店会制造并交付给客户,所以很少出现两个相同的产品,tblCustomerProduct需要吗?
【问题讨论】: