简单的 UML 行为让我感到困惑!
对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另外,如果关联是可选的,则它不是组合。它至多是一个聚合,甚至是一个简单的关联,正如我在该图中所示的那样。
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.
让我们从简单的开始:
像编写程序一样对类进行建模。创建一个 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.