我正在从C++代码开发一个UML类图。我有一个没有类的头文件,它基本上是一个定义文件(它有结构、枚举和定义的常量)。一般来说,我知道如何表示结构和枚举,但我不清楚如何在类图中表示(或者是否应该表示)常量。另外,我很好奇结构、枚举和常量是否应该是更大的容器的一部分?(比如引用名称空间助手或定义(H))
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <stdint.h>
#include <string>
namespace helper
{
enum Colors
{
Red = 0,
Blue,
Green
};
struct volunteer
{
std::string FirstName;
std::string MiddleName;
std::string LastName;
std::string Occupation;
};
typedef const std::string Constant;
Constant Foo = "Foo";
Constant Bar = "Bar";
Constant Bat = "Bat";
}
#endif
发布于 2017-06-26 16:37:17
类图应该显示实体级模型。常量是一个次要的实现细节,从逻辑上讲,它不是类的成员,它在OO视图中没有任何意义。所以答案是“你不需要”。
发布于 2017-07-14 14:04:04
您的一些helper
信息可以这样建模:
UML中存在常量的概念,但它通常在类中,并且有一个类型。请参阅上图中的Employee
类。
发布于 2017-06-26 16:36:59
我会将它们表示为类常量或std::string的对象(或IBM术语中的“实例”)(无论哪个看起来更合适)。对象符号可以在名称下面添加值。如果需要,可以将值标记为{只读}。
https://softwareengineering.stackexchange.com/questions/351626
复制相似问题