简体   繁体   English

Uml序列图:与默认构造函数比较绘制新的运算符

[英]Uml Sequence Diagram: Drawing new operator in comparison with default constructor

Could someone tell me the how to draw the differences in a sequence diagram with the following C++ code example. 有人可以告诉我如何使用下面的C ++代码示例在序列图中绘制差异。 I tried to be as clear as possible:) 我试图尽可能清楚:)

main 主要

#include "classa.h"

int main()
{
    ClassA a;
    return 0;
}

classa.h

#ifndef CLASSA_H
#define CLASSA_H
#include "classb.h"

class ClassA
{
public:
    ClassA();
    ~ClassA();
private:
    ClassB *var1;
    ClassB var2;
};

#endif // CLASSA_H

classb.h

#ifndef CLASSB_H
#define CLASSB_H

class ClassB
{
public:
    ClassB();
    void test();
};

#endif // CLASSB_H

classa.cpp 类cpp

#include "classa.h"

ClassA::ClassA()
{
    var1 = new ClassB;
    var1->test();
    var2.test();
}

ClassA::~ClassA()
{
    delete var1;
}

classb.ccp classb.ccp

#include "classb.h"

ClassB::ClassB()
{
}

void ClassB::test()
{
    //Here some code
}

I Think the image below is used for the new operator (var1), but how is var2 drawn? 我认为下面的图像用于新运算符(var1),但是如何绘制var2?

UML图

My c++ is a bit rusty but I think something like this: 我的c ++有点生锈,但我认为是这样的: 顺序图

var2 gets allocated automatically when a is created - so is created before var1 . var2在创建a时自动分配-因此在var1之前创建。 As far as UML is concerned, it's still creation of a new class instance. 就UML而言,它仍然是创建新的类实例。 There may be ways to further stereotype the <<create>> operation to indicate creation on the stack vs. heap but can't say I've ever used them. 也许可以通过一些方法进一步构造<<create>>操作,以指示在堆栈还是堆上的创建,但是不能说我曾经使用过它们。 Like I say though, my C++ is a bit rusty. 就像我说的那样,我的C ++有点生锈。

hth. hth。

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

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