0

alt text

Can someone check my class diagram because I am not too good at drawing this type of uml diagram

  1. A User can be a PersonalUser or a BusinessUser
  2. An Administrator is a special type of PersonalUser
  3. A PersonalUser or BusinessUser can create many Auction
  4. But an Auction can be created by only one PersonalUser or only one BusinessUser
  5. There an Auction cannot exist without an PersonalUser or a BusinessUser
  6. An Auction can contain only one Item
  7. An Item can be in only one Auction
  8. An Item cannot exist without an Auction
  9. An Auction cannot exist without an Item
  10. An Item has one Category
  11. Category can has many item
  12. An Item cannot exist without a category
  13. A Category can has a Parent Category but this is not mandatory
  14. A Category can has many Attributes
  15. But an Attribute is for only one Category
  16. An Attribute cannot exist a Category
  17. An Attribute can has many AttributeOption
  18. But an AttributeOption is linked to only one Attribute
  19. An AttributeOption cannot exist without an Attribute
  20. An Auction can has many bids
  21. A bid is only for one auction
  22. A Bid cannot exist without an Auction and a Personal User or a BusinessUser
  23. An Item can has many picture
  24. A picture is only for once item and a picture cannot exist without an Item
  25. A User can create many ForumTopics but a ForumTopic can be created only by one User
  26. A ForumTopics can contain one or more ForumMessage
  27. A ForumTopic cannot exist without a User and a ForumMessage cannot exist without a ForumTopic
  28. A BusinessUser can has many BusinessContactNumber but a BusinessContactNumber is only for one BusinessUser
  29. A BusinessContactNumber cannot exist without a Business
4

2 回答 2

5

乍一看,您使用了很多聚合。这是相当少见的。我从来没有见过一个很好的例子来说明什么时候聚合是合理的。它通常是一个简单的关联(没有整体关系)或组合(当整体被删除时,部分被删除)。

不能不存在并不意味着聚合。适当的多重性就足够了。可以创建并不意味着聚合。除非创建者和创建之间存在关联(在这种情况下不需要明确提及创建),否则创建通常使用适当的定型使用关系(即虚线箭头)建模。

4 但拍卖只能由一个 PersonalUser 或一个 BusinessUser 创建。

那么 Auction-PersonalUser 关联的多重性在 PersonalUser 端不能为 1(因为 Auction 可能是由 BusinessUser 创建的)并且 Auction-BusinessUser 关联的多重性在 BusinessUser 端不能是 1(原因大致相同)。使用 0..1 作为多重性,但要注意我将写的关于 3 的内容。

3 PersonalUser 或 BusinessUser 可以创建多个 Auction

这相当于一个 User 可以创建多个 Auction

6 拍卖只能包含一件物品

7 一件物品只能在一次拍卖中

8 没有拍卖,物品就无法存在

9 没有物品就无法进行拍卖

然后在 Item 和 Auction 之间有一个单一的关联,两端的重数为 1。不要对其进行聚合,也不要为它使用两个关联。

13 一个类别可以有一个父类别,但这不是强制性的

如果您标记关联结束,那将很清楚。

25 一个用户可以创建多个论坛主题,但一个论坛主题只能由一个用户创建

这仅与拍卖有模糊的关系,也可能独立于它们而存在。将论坛内容放入单独的包中。那么也许拍卖的东西和用户的东西也应该得到一个单独的包。

顺便说一句:你没有提到投标服务。单纯的建模这些对象的概念似乎并不凭空存在,它们实际上是被某些软件使用的。在这种情况下,请忽略它。

于 2011-01-22T15:35:46.233 回答
1

我在很大程度上同意之前的受访者,所以我将只提出不同之处和补充意见。

更准确地说,“可以创建...”应该使用依赖关系(而不是使用)来描述。

  1. 如果应该存在一些区别,它并不完全等同。如果您出于某种原因想要避免枚举,则可以将 User 类与枚举或 UserType 类一起使用。

6.-9。所以不能存在 Auction 或 Item 对象。要么以一种方式放松关系并使用组合,要么将这两者合并为一个类,或者创建一个关联类。

  1. 也许一个类别可以包含许多子类别?如果为真,则编辑相应的多重性。

  2. 同4.,查看其他答案。

还要重新考虑设计中的类数量。类不仅仅是数据持有者,它们应该有行为。AttributeOption 或 Attribute 或 BusinessContact 等的行为是什么?Getter 和 setter 不计入行为......我猜你计划在 BidingService 中拥有所有这些行为,所以我建议你删除它并根据哪些对象类应该负责通过各自的方法。

于 2011-01-27T23:58:08.067 回答