0..* 1..*
+-------+ +--------+
|Invoice|_______________________|Products|
+-------+ | +--------+
|inID | | |proID |
|inDate | | | Qty |
+-------+ | | Price |
| +--------+
+-----------+
|LineProduct|
+-----------+
| Qty |
| salePrice |
+-----------+
这个编码对于上面的类图是否正确?
Class Invoice
{
inID:int;
inDate:Date;
}
Class LineProduct
{
Qty:int;
salePrice:int;
//inID:int; <-- this is what I did but I am wrong
//prodID:int; <-- this is what I did but I am wrong
}
Class Products
{
prodID:int;
Qty:int;
Price:int;
}
现在,例如,如果发票包含两个产品,我必须将对象实例传递给DB函数,例如
invoiceTable.saveInvoice(invoice:Invoice);
lineproductTable.saveLine( product instance 1 );
lineproductTable.saveLine( product instance 2 );
现在又一次混淆了行产品表将包含inID和proID列,但是如何传递一个具有inID和prod ID的对象?
PS:对不起,我被困在低位代表我无法张贴图片并解释我的困惑
答案 0 :(得分:2)
我认为你首先做对了。
//inID:int; <-- this is what I did but I am wrong
//prodID:int; <-- this is what I did but I am wrong
取消注释这些行。这是将产品与发票相关联的唯一方法。