Uml 序列图:绘制新运算符与默认构造函数的比较
有人可以告诉我如何使用以下 C++ 代码示例在序列图中绘制差异。我试图尽可能清晰:)
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
#include "classa.h"
ClassA::ClassA()
{
var1 = new ClassB;
var1->test();
var2.test();
}
ClassA::~ClassA()
{
delete var1;
}
classb.ccp
#include "classb.h"
ClassB::ClassB()
{
}
void ClassB::test()
{
//Here some code
}
我认为下图用于 new 运算符(var1),但是 var2 是如何绘制的?
Could someone tell me the how to draw the differences in a sequence diagram with the following C++ code example. 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
#include "classa.h"
ClassA::ClassA()
{
var1 = new ClassB;
var1->test();
var2.test();
}
ClassA::~ClassA()
{
delete var1;
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 C++ 有点生疏,但我认为是这样的:
var2
自动分配当a
创建时 - so 在var1
之前创建。就 UML 而言,它仍然是创建一个新的类实例。可能有一些方法可以进一步构造<>
操作来指示在堆栈上创建还是在堆上创建,但不能说我曾经使用过它们。就像我说的,我的 C++ 有点生疏了。嗯。
My c++ is a bit rusty but I think something like this:
var2
gets allocated automatically whena
is created - so is created beforevar1
. As far as UML is concerned, it's still creation of a new class instance. 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. Like I say though, my C++ is a bit rusty.hth.