关于 UML 类图中属性如何工作的困惑

发布于 2025-01-01 23:12:22 字数 345 浏览 1 评论 0原文

我在斯德哥尔摩大学学习了面向对象系统和设计课程。我必须交一份额外的作业,其中我必须创建一个 UML 类图来反映一个销售汽车的网站(这不是我要求您做作业的线程)。这是我提交的:

Description

老师说“这不是你使用属性的方式”,并且似乎不愿意解释我应该采取不同的做法。全部都是瑞典语,但我认为无论语言如何,要点都很清楚。

我的问题是:应该如何以不同的方式建模?我对一些对象、枚举进行了聚合,因为网站对某些类的属性数量有限。

非常感谢任何帮助。

亲切的问候,

雨果

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:

Description

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小清晰的声音 2025-01-08 23:12:22

我在您的图表中看到一些问题:

  • 我相信您的图表中有一些未正确定义的枚举。枚举应该类似于这个
  • 除了聚合之外,您还可以定义属性(例如,Bil 与此 SäkerhetsTilägg 具有聚合关系,并且另外定义属性 säkerhet。您应该使用关系或属性,请参阅 此处
  • 。您说 Bil 可以有任意数量的 SäkerhetsTilägg,而属性 säkerhet 只包含一个SäkerhetsTilägg
  • ,您必须定义属性和方法的可见性(例如+-等)。

I see some problems in your diagram:

  • I believe you have some enumerations in your diagram that are not defined properly. An enumeration should look like this.
  • You define attributes in addition to aggregation (e.g. the Bil has a aggregation relation to this SäkerhetsTilägg, and additionally defines an attribute säkerhet. You should either use a relation or an attribute, see here.
  • While we are at this, the multiplicities are somewhat confusing. You say that Bil can have any number of SäkerhetsTilägg, while the attribute säkerhet holds exactly one SäkerhetsTilägg.
  • Afaik, you have to define the visibility of attributes and methods (like +, - etc).
夜深人未静 2025-01-08 23:12:22

在我看来,您已经将枚举建模为类。尽管从视觉上看,枚举看起来像带有 <> 的类。构造型,这实际上是完全不同的事情,当属性用于类时,它在隔间中有 EnumerationLiterals。

在 ArgoUML 中,您可以使用工具栏右侧第四个按钮创建枚举。这是一个下拉菜单,默认用于创建新的数据类型,但如果将其下拉并选择绿色矩形,它将创建一个枚举。首先创建枚举,您可以选择它们作为属性的类型。

最终结果应如下所示:
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:
ArgoUML enumeration homework

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文