关于 UML 类图中属性如何工作的困惑
我在斯德哥尔摩大学学习了面向对象系统和设计课程。我必须交一份额外的作业,其中我必须创建一个 UML 类图来反映一个销售汽车的网站(这不是我要求您做作业的线程)。这是我提交的:
老师说“这不是你使用属性的方式”,并且似乎不愿意解释我应该采取不同的做法。全部都是瑞典语,但我认为无论语言如何,要点都很清楚。
我的问题是:应该如何以不同的方式建模?我对一些对象、枚举进行了聚合,因为网站对某些类的属性数量有限。
非常感谢任何帮助。
亲切的问候,
雨果
I've taken the course Object Oriented System and Design at Stockholm University. I had to hand in an extra assignment where I had to create a UML Class Diagram reflecting a web site that sold cars (this is not a thread where I'm asking you to do my homework). This is what I handed in:
The teacher said that "this isn't how you use attributes" and seems reluctant to explaining what I should have done differently. It's all in Swedish but I think that the main points are clear regardless of language.
My question is: How should this have been modeled differently? I have aggregation for some objects, enums because the website had a limited amount of attributes for some classes.
Any help is greatly appreciated.
Kind regards,
Hugo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在您的图表中看到一些问题:
Bil
与此SäkerhetsTilägg
具有聚合关系,并且另外定义属性säkerhet
。您应该使用关系或属性,请参阅 此处Bil
可以有任意数量的SäkerhetsTilägg
,而属性säkerhet
只包含一个SäkerhetsTilägg
+
、-
等)。I see some problems in your diagram:
Bil
has a aggregation relation to thisSäkerhetsTilägg
, and additionally defines an attributesäkerhet
. You should either use a relation or an attribute, see here.Bil
can have any number ofSäkerhetsTilägg
, while the attributesäkerhet
holds exactly oneSäkerhetsTilägg
.+
,-
etc).在我看来,您已经将枚举建模为类。尽管从视觉上看,枚举看起来像带有 <> 的类。构造型,这实际上是完全不同的事情,当属性用于类时,它在隔间中有 EnumerationLiterals。
在 ArgoUML 中,您可以使用工具栏右侧第四个按钮创建枚举。这是一个下拉菜单,默认用于创建新的数据类型,但如果将其下拉并选择绿色矩形,它将创建一个枚举。首先创建枚举,您可以选择它们作为属性的类型。
最终结果应如下所示:
It looks to me like you've got your Enumerations modeled as Classes. Even though visually an Enumeration looks like a Class with an <> stereotype, it's really a different thing altogether and it has EnumerationLiterals in the compartment when Attributes would be for a Class.
In ArgoUML you can create an Enumeration using the fourth button from the right on the toolbar. It's a dropdown menu which defaults to creating a new Datatype, but if you pull it down and select the green rectangle, it'll create an Enumeration. Create your Enumerations first and they'll be available for you to select as the type for your Attributes.
The final result should look like this: