我有两张桌子: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
需要吗?