开发者

best way to model the following scenario

开发者 https://www.devze.com 2023-04-13 08:19 出处:网络
I am starting of in the world of DD and am attempting to build a simple enough application. I have a few questions on how I am choosing to model my domain.

I am starting of in the world of DD and am attempting to build a simple enough application. I have a few questions on how I am choosing to model my domain.

My application allows users to order greeting cards. The user can order any number of cards in one order. When choosing a card to order they browse the card catalogue. THe card catalogue however is not stored locally, its retrieved from an external system, however every card they have browsed to in their current session will be cached locally in the database for the lifetime of 开发者_开发技巧that session in case they wish to add to the order.

When they add a card to the order, it goes on a new order line item. THey then must specify some other details for the order line item, colour, greeting etc...

My question is this: How do I model the card in my domain. I have Order as an aggregate root, with many order line items. Each order line item will have certain attributes, and a card.

However my card catalogue will also have a card concept which will have the same properties as the card on my order line item.

Am I correct in modelling these cards as 2 seperate entities (CatalogueCard and OrderCard) even though they have the same set of properties?

The same question could be posed also for the address a card must be addressed to(each order line item will have an address) and the billing address for the order. Should these be modelled as completley seperate entities?

Thanks in advance


The fact that you're seeing business entity concepts repeated as you model your domain means that you're probably on the right track. But if you have two objects with the same set of attributes you should definitely just use one. CatalogueCard and OrderCard should be instance names, not class names, except if you expect some change then you can inherit from a base Card class. Same goes for your address class. Just use one address class. The address type should just be another attribute which could be an enum value of the types of addresses your model supports.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号