简体   繁体   English

如何在类图中使用聚合关系?

[英]How to use aggregation relationship in class diagram?

I have some strange question. 我有一个奇怪的问题。

I have a class that composed of 2 classes. 我有一个由2个班级组成的班级。

But the main class has not any methods or attributes. 但是主类没有任何方法或属性。 only the aggregate classes. 仅聚合类。

I want to access the 2 other classes using the main class without creating objects directly from them in the main program 我想使用主类访问其他2个类,而不直接在主程序中从它们创建对象

Creating objects from the 2 classes is permitted only to the main class and not allowed to the other 2 classes 从这两个类创建对象仅允许进入主类,而不允许其他两个类创建对象

How to do that? 怎么做?

It seems to me that you want to use nested classes. 在我看来,您想使用嵌套类。 You just need to declare the classes as private and you're good to go. 您只需要声明这些类为私有类就可以了。 https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM