我正在开发一个库存系统,我需要帮助设计一个产品(项目)表,根据以下要求。
我的问题是我怎么处理这件事?我应该为所有这些类型的晋升创建单独的表,还是在相同的表中我可以处理所有这些?
发布于 2013-09-24 20:33:36
首先,您在这里描述的是行为,而不是数据存储。因此,尽管如何将其存储在数据库中是很重要的,但您最关心的应该是如何编写这方面的代码。
因此,作为c#中的一个例子
public class Product {
public string Name { get; set; }
public decimal UnitCost { get; set; }
public List<IPromotion> { get; set; }
}
public interface IPromotion {
decimal CalculateTotalDiscount(Product p, int quantity);
}
public class BuyAndGetFreePromotion : IPromotion {
public int QuantityRequiredToGetPromotion { get; set; }
public int NumberOfUnitsFree { get; set; }
public decimal CalculateTotalDiscount(Product p, int quantity) {
if (QuantityRequiredToGetPromotion == quantity) {
return (p.UnitCost * quantity) - (p.UnitCost * NumberOfUnitsFree );
}
return 0;
}现在,您可以执行每个类的表类层次结构或表。这在很大程度上取决于您使用的ORM (如果有的话)。
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/inheritance.html http://my.safaribooksonline.com/book/web-development/ruby/9780132480345/advanced-active-record/ch09lev1sec5#title-ID0EBYHK
至于这个问题。我不认为2%的折扣是作为促销储存的,而是由发票/账单负责。因此,是否有多张表格的决定应该基于不同类型的促销活动,以及是否可以在一个表中对它们进行建模和一致存储。您有更多的推广示例吗?我想说,一个表是完全可以接受的。
https://stackoverflow.com/questions/18990312
复制相似问题