我有两个表: 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
需要什么?