简体   繁体   English

实现 UML 序列图

[英]Implementing UML Sequence Diagram

My question is relatively simple: how would I go about implementing a UML sequence diagram in C++ code?我的问题相对简单:我将如何在 C++ 代码中实现 UML 序列图? I was reading up on sequence diagrams the other day, and I found this example for a program for a student enrolling in a seminar.前几天我正在阅读序列图,我发现这个例子是为参加研讨会的学生准备的程序。

How would I go about turning this diagram into a program?我将如何将这个图表变成一个程序? For the sake of this question, lets focus on one class, say the EnrollInSeminar controller.为了这个问题,让我们关注一个类,比如EnrollInSeminar控制器。 How would I go about implementing this?我将如何实施这个?

I imagine that it might be something like this:我想它可能是这样的:

class EnrollInSeminar
{
public:
  void Activate();
};

void EnrollInSeminar::Activate()
{
  SecurityLogon logonUI{};
  Student theStudent = logonUI.getStudent();
  SeminarSelector seminarSelectorUI{};
  Seminar seminar = seminarSelectorUI.getSeminar();
  if (!seminar.isEligible(theStudent))
    return;
  theStudent.getSchedule().determineFit(seminar);
  Fee fee = StudentFees.calculateFees(seminar, theStudent);
  FeeDisplay feeUI{fee};
  if (!feeUI.getVerification())
    return;
  seminar.enrollStudent(theStudent);
}

Is this the correct way to implement the EnrollInSeminar class?这是实现EnrollInSeminar类的正确方法吗? If not, how should I do it?如果没有,我该怎么做?

Actually a SD does not tell anything about the methods being used in the messages passed from one object to another except the name, the parameters and - as the name says - the sequence.实际上,除了名称、参数和(顾名思义)序列之外,SD 并没有说明从一个对象传递到另一个对象的消息中使用的方法。 So the only thing you can draw from "just the SD" are methods and their parameters.因此,您可以从“仅 SD”中得出的唯一内容是方法及其参数。

You will need additional information from a use case to know what the methods are all about.您将需要来自用例的其他信息来了解这些方法的全部内容。 Without you simply can not "implement a SD".没有你根本无法“实施 SD”。

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

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