简单的 UML 行为让我感到困惑!

发布于 2024-08-11 20:57:46 字数 282 浏览 5 评论 0原文

对 UML 和系统设计非常陌生。

我们正处于设计阶段绘制类图的阶段,并且正在努力弄清楚如何实现需求。问题是:

我们有一个 Person 类,它由 Name 类和 ContactDetails 类组成。联系人详细信息类由 MobileNumber 和 EmailAddress 类组成。

我将如何对我的类图进行建模,以便 ContactDetails 必须具有 MobileNumber 或 EmailAddress 或两者都有?

我确信这很简单 - 但它让我困惑!

谢谢

Very new to UML and system design.

We're at the stage of doing a class diagram in the design phase and are struggling to figure out how to implement a requirement. Here's the problem:

We have a Person class that is composed of a Name class and a ContactDetails class. Contact details class is composed of a MobileNumber and an EmailAddress class.

How would I model my class diagram so that ContactDetails must have either MobileNumber or EmailAddress or both?

I'm sure it's simple - but it's thrown me!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

情痴 2024-08-18 20:57:46

alt text

另外,如果关联是可选的,则它不是组合。它至多是一个聚合,甚至是一个简单的关联,正如我在该图中所示的那样。

alt text

Also, if an association is optional, it is not a composition. It is at most an aggregation, or even a simple association as I show in this diagram.

雨巷深深 2024-08-18 20:57:46

让我们从简单的开始:

像编写程序一样对类进行建模。创建一个 ContactDetails 类并添加两个属性“MobileNumber”和“EmailAddress”,这两个属性都是相应的类型。
现在创建构造函数方法:

+ContactDetails(mn MobileNumber)
+联系方式(电子邮件地址)
+ContactDetails(mn MobileNumber, email EmailAddress)

现在:如何在代码中添加所需的约束?

通过将空构造函数设置为私有?这样做!

-ContactDetails()

通过检查参数不为空?只需添加一个 Constraint 元素,它基本上只是您的类的文本注释。

就是这样。

let's start simple:

Model your classes as you would write your program. Create a ContactDetails class and add two attributes "MobileNumber" and "EmailAddress", both of the corresponding type.
Now create your constructor methods:

+ContactDetails(mn MobileNumber)
+ContactDetails(email EmailAddress)
+ContactDetails(mn MobileNumber, email EmailAddress)

Now: how would you add the needed constraint in code?

By setting the empty constructor as private? Do so!

-ContactDetails()

By checking that the parameters are not empty? Just add a Constraint element which basically just a text note to your class.

That's it.

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