我可以在编写编码时省略多重性和角色名称吗 [英] Can I ommit the multiplixity and role name in writing coding
本文介绍了我可以在编写编码时省略多重性和角色名称吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将设计转换为代码时,可以省略多重性和角色名称.
如果不能,我该怎么写.
请对此进行讨论.
谢谢您,
When I convert design to code ,can I ommit the multiplixity and role name .
If I cannot ,how can I write this .
Plese discuss about this .
Thanks you,
推荐答案
如果我对您的理解正确,那么答案是否定的,您不必必须包含它们,但是您可以" d如果您忽略了它们,那将是一个很大的错误.
让我们考虑人.具体而言,人与人之间的关系.您可以负担零个或一个配偶,两个父母和尽可能多的孩子.您将为谁编码?如果多重性可以大于1,则它必须是数组或某种类型的集合.否则,每个角色都可以由一个简单的引用变量填充:
If I understand you correctly, then the answer is no, you do not have to include them but you''d be making a big mistake if you omitted them.
Let us consider people. Specifically, relationships between people. There can be zero or one spouse, two parents and as many children as you like / can afford. Who would you code this? If the multiplicity can be greater than 1 it must be either an array or a collection of some sort. otherwise each role can be filled by a simple reference variable:
public class Person {
/** The spouse of this person */
private Person spouse;
/** The mother of this person */
private Person mother;
/** The father of this person */
private Person father;
/** The children of this person */
private List<Person> children;
}
注意角色是如何导入成员变量 name 的.它不是必须的,您可以使用hatstand
代替children
;该变量也将起作用;但要了解它的作用并不容易.
Note how the role leads into the member variable name. It doesn''t have to, you could have hatstand
instead of children
; the variable would work just as well; but it isn''t easy reading it to know what it does.
这篇关于我可以在编写编码时省略多重性和角色名称吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文