在另一个class中创建一个对象,UML class图中的关系是什么?
Creating an object of one class in another, what is the relationship in a UML class diagram?
我有一个 SessionManager class,我在每个 class 用户需要登录才能访问的对象中创建我不确定这里创建的关系类型,因为我似乎对网上的所有定义感到困惑。我正在尝试创建一个 UML class 图来表示我的应用程序中的所有 classes。这是聚合关系还是关联关系?
我没有 class 相互扩展,因为我制作了一个 Android 应用程序,该应用程序使用意图从 activity 传递到 activity,我是只需在其他 classes 中创建一些 classes 的对象。
此外,有没有什么方法可以在 UML class 图上表示意图?
正在创建 SessionManager 对象:
SessionManager sessionManager;
在 onCreate 方法中使用 SessionManagerClass 中的 checkLogin() 方法:
sessionManager = new SessionManager(this);
sessionManager.checkLogin();
会有HAS-A
的关系,也就是聚合。
Aggregation is a special form of association. It is a relationship between two classes like association, however its a directional association, which means it is strictly a one-way association. It represents a HAS-A relationship
UML 构建演示
更多信息:
我认为这种情况下的组合关系是正确的。
class A {
private B b = new B();
}
//or
class A {
private B b;
public A() {
b = new B();
}
}
复合聚合是关于运行时的。组合元素将与组合元素一起销毁。第 17 页的 table。 UML 2.5 状态中的 110 个
composite | Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects (see the definition of parts in 11.2.3).
在您的案例中模拟这个(关联端的实心菱形)似乎是合适的。 SessionManager
应该是某种工厂,生产它负责的 Session
对象。
我有一个 SessionManager class,我在每个 class 用户需要登录才能访问的对象中创建我不确定这里创建的关系类型,因为我似乎对网上的所有定义感到困惑。我正在尝试创建一个 UML class 图来表示我的应用程序中的所有 classes。这是聚合关系还是关联关系?
我没有 class 相互扩展,因为我制作了一个 Android 应用程序,该应用程序使用意图从 activity 传递到 activity,我是只需在其他 classes 中创建一些 classes 的对象。
此外,有没有什么方法可以在 UML class 图上表示意图?
正在创建 SessionManager 对象:
SessionManager sessionManager;
在 onCreate 方法中使用 SessionManagerClass 中的 checkLogin() 方法:
sessionManager = new SessionManager(this);
sessionManager.checkLogin();
会有HAS-A
的关系,也就是聚合。
Aggregation is a special form of association. It is a relationship between two classes like association, however its a directional association, which means it is strictly a one-way association. It represents a HAS-A relationship
UML 构建演示
更多信息:
我认为这种情况下的组合关系是正确的。
class A {
private B b = new B();
}
//or
class A {
private B b;
public A() {
b = new B();
}
}
复合聚合是关于运行时的。组合元素将与组合元素一起销毁。第 17 页的 table。 UML 2.5 状态中的 110 个
composite | Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects (see the definition of parts in 11.2.3).
在您的案例中模拟这个(关联端的实心菱形)似乎是合适的。 SessionManager
应该是某种工厂,生产它负责的 Session
对象。