0

经过多年的编程,我开始使用 UML,我想确保我正确使用图表中的符号。

下图是否看起来像一个简单的 Car 类的正确表示?

原始模型

更新:

实际上,我只是意识到 Make 知道模型,所以我删除了箭头,但是 Make 和 Model 不知道 Car,所以我添加了箭头:

修正模型

4

1 回答 1

2

I would make some adjustments to your original diagram:

Make

  • The Make identifies the manufacturer, so Make will have many Models, and because no other manufacturer can take ownership of those models, the black diamond is shown to denote composition
  • The relationship is bidirectionally navigable, so no arrows are shown
  • Because we can navigate from Make to Model, there is a SortedSet (sorted by year) of Models shown in Make

Model

  • Model holds the only direct relationship to Make; this guarantees the validity of the relationships and avoids incorrect connections that could result from allowing other classes to create relationships with Make
  • Because Model may be used to navigate to Make, Model contains a reference to its Make; this ensures that any Car may navigate to its Model information and from there (and only there) navigate to its Make
  • For year, the immutable type Integer was chosen, because the value will never change once it has been assigned

Car

  • The relationship between Model and Car is only navigable from Car to Model, because the business domain has no need to obtain a set of all Cars that mere manufactured for any given Model (and it keeps things simpler)
  • Each car is assigned a VIN, shown as an instance of UUID - Universally Unique Identifier
  • The relationship between Car and Engine is only navigable from Car to Engine, so Car has an Engine member; there are use cases where parts of the system that receive a reference to a Car may want to navigate to the Car's Engine

Engine

  • Given that an Engine may start its life in one Car but then be moved into a different Car, the relationship is shown using a white diamond, denoting aggregation
  • The Engine is assigned a Part Number, which is a specific identifier for that instance of Engine; therefore the immutable type String is shown
  • The Engine maintains a mileage counter, which is defined to be of type: int, because the value is mutable and will change over the lifetime of the Engine

enter image description here

I hope this is helpful and provides some good feedback that makes your modeling exercise thought provoking. I know I had fun creating the diagram and thinking about the relationships and some of the details. Haven't done this in awhile -

于 2012-04-27T04:27:12.093 回答