我是業務邏輯組件,使客戶可以在網上訂購。到目前爲止,我簡單的商業邏輯是這樣的:訂單和訂單明細
public class Product
{
public int productID { get; }
public string name { get; set; }
//other properties here like address and such
}
public class Order
{
public int orderID { get; }
public Customer customer { get; set; }
public List<Product> OrderItems { get; set; }
//other properties go here
}
的Products
List不支持包含多個批量的產品訂單。我如何在這裏添加支持?我如何從客戶端調用它?
感謝您的答覆。 'Dictionary'總是需要一個密鑰,該密鑰必須是唯一的。這種情況下關鍵是什麼? – Victor 2012-02-03 20:46:35
您應該使用ProductID作爲關鍵字(假設您只希望您的訂單中的每個產品都有一次)。它是一個整數,因此計算Dictionary內部使用的散列速度非常快,您也可以知道產品是否已經在您的訂單中。 – Jay 2012-02-03 20:50:15
@Jay - 啊,所以它是'Dictionary'。是的,Dictionary在搜索時比列表快得多,但是當您實際下訂單時,它不會增加複雜性,因爲客戶現在需要知道他們選擇的每個項目的產品ID? –
Victor
2012-02-03 21:04:44