我如何描述一个指向UML类图中的类的指针? [英] How can I describe a pointer to class in a UML class diagram?

查看:439
本文介绍了我如何描述一个指向UML类图中的类的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个类A 包含指向类B 的指针和一个接受输入的方法指向 B类的指针

If I have a class A wich contains a pointer to a class B and a method wich takes in input a pointer to class B

class A {
private:
    B* attribute;
public:
    void method(B* par);
}

如何在UML类图中描述它?我要用*吗?它是什么样的组合?

how can I describe it in a UML class diagram? Have I to use * ? What kind of composition is it?

推荐答案

在UML中,显示它是否是一个指针并不重要。为什么?因为,你可能正在使用UML描述一个没有指针的语言。

In UML it is not as important to show whether it is a pointer or not. Why? Because, you may be using UML describing an OOD for a language without pointers.

快速答案:从你的代码,A聚合B(A类的空菱形,连接B与实线)。这是因为没有析构函数删除 指针引用

Quick answer: from your code, A aggregates B (empty diamond at A class, connecting B with a solid line). That is because there is no destructor that deletes what A.attribute pointer references.

真正重要的是说什么是生命周期引用对象。因此,对于在所有者销毁时死亡的引用对象(有关系),您必须使用实体(填充)菱形。这称为组合。因此,所有者必须管理所拥有对象的生命时间。一个这样的例子是人类有手。

What is really important is to say what is the lifetime of the referenced object. So, for a referenced object (has relationship) that dies when the owner is destroyed, you have to use a solid (filled) diamond. This is called composition. So the owner has to manage the life time of the owned object. One such example is human has hands. The hands do not survive when the human object is destroyed.

钻石未填充(聚合)时,所有者不负责任以管理所拥有的对象的生命。例如,你不会期望看到拥有的对象在析构函数中被删除。雇主有一个TeamLeadRole,但是当雇主被销毁(即离开公司)时,TeamLeadRole仍然可用。

When the diamond is not filled (aggregation), then the owner is not responsible to manage the life of the object owned. For example you will not expect to see that the owned object being deleted in the destructor. An employer has a TeamLeadRole, but when the employer is "destroyed" (i.e. left the company) then the TeamLeadRole is still available.

现在,钻石,你通常(不是所有的时间)将有价值的对象。当你看到一个空的钻石,你可以使用引用或指针。

Now, traditionally when you see a filled diamond, you usually (not all the time) will have an object by value. Where when you see an empty diamond you may use reference, or pointer.

如果你的类使用另一个类,但不保留实例(或引用/指针) ,那么您可以通过对象之间的简单线(实线)来表示依赖性。这意味着有一种关系称为关联

If your class uses another class but does not keep instances (or references/pointers) to that class, then you can denote dependency by just a simple line (solid) between the objects. That means there is a relationship is called association.

这篇关于我如何描述一个指向UML类图中的类的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆