[英]Grails Domain Design: inheritance or one class with nullable properties?
I have a domain OrderItem 我有一个域OrderItem
class OrderItem {
Product product
Packaging packaging
//other details
}
class Product {
//other details
}
class Packaging {
//other details
}
Currently, OrderItem refers only to Beers . 当前,OrderItem仅指Beers 。 Product is the type of beers.
产品是啤酒的类型。 Packaging is the cans/bottles/keg/etc.
包装是罐/瓶/桶/等。
Then the client decides to also sell items that are not beers: Spirits, Ingredients, Souvenirs, etc. 然后,客户决定也出售非啤酒的产品:烈酒,食材,纪念品等。
I'm thinking that these are all OrderItem objects, but the system currently treats OrderItem as Beers. 我认为这些都是OrderItem对象,但是系统当前将OrderItem视为Beers。 How should I introduce the expanded models?
我应该如何介绍扩展模型? (Note: Some of the new items don't have product, packaging or both.)
(注意:某些新商品没有产品,包装或两者都没有。)
I prefer the second one, adding additional property like category
or itemType
. 我喜欢第二个, 添加其他属性,例如
category
或itemType
。
So when adding the new field your migration script must set the itemType
field value to Beers
for all the existing records( Because all the products you had are all Beers
). 因此,在添加新字段时,迁移脚本必须为所有现有记录将
itemType
字段值设置为Beers
(因为您拥有的所有产品都是Beers
)。
I dont know which of your fields are going to be null
, but if your OrderItem
table is still having many nullable
columns you need to to normalize it. 我不知道您的哪个字段将为
null
,但是如果您的OrderItem
表仍然具有许多nullable
列,则需要对其进行规范化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.