APP下载

基于活动图与顺序图的自动代码生成

2021-09-06文浩,蒋建民,张仕,洪中

软件工程 2021年8期

文浩,蒋建民,张仕,洪中

摘  要:在模型驱动开发过程中,为了减轻开发人员的负担,通常采用自动工具生成代码框架。本文提出了一种基于活动图与顺序图自动生成代码框架的方法,并且基于该方法开发了原型工具。首先,给出了活动图和顺序图的形式化表达;其次,基于活动图和顺序图模型提出了三个实现自动代码生成的算法,该算法是通过活动图来描述对象内部的活动次序,并且利用顺序图体现对象之间的交互;最后,给出了一个原型工具,实现了模型到代码框架的自动转换。该工作可以确保转换的正确性,并且提高软件开发效率。

关键词:模型驱动开发;自动代码生成;形式化方法

中图分类号:TP311.5     文献标识码:A

Automatic Code Generation based on Activity and Sequence Diagrams

WEN Hao1,2, JIANG Jianmin3, ZHANG Shi1, HONG Zhong1

(1.College of Computer and Cyber Security, Fujian Normal University, Fuzhou 350117, China;

2.Chengdu Institute of Computer Applications, Chinese Academy of Sciences, Chengdu 610041, China;

3.College of Software Engineering, Chengdu University of Information Technology, Chengdu 610225, China)

caswh96@foxmail.com; jjm@cuit.edu.cn; shi@fjnu.edu.cn; fjfzhz@fjnu.edu.cn

Abstract: In the process of model-driven development, automatic tools are usually used to generate code frameworks in order to reduce the burden on developers. This paper proposes a method to automatically generate code framework based on activity diagram and sequence diagram, and a prototype tool is developed based on this method. First, this paper gives a formal expression of activity diagrams and sequence diagrams; secondly, three algorithms for realizing automatic code generation are proposed based on the activity diagram and sequence diagram. The algorithm uses activity diagrams to describe the internal activity sequence of the object and uses the sequence diagram to reflect the interaction between the objects; finally, a prototype tool is given to realize the automatic conversion from the model to the code framework. This work can ensure the correctness of the conversion and improve the efficiency of software development.

Keywords: model-driven development; automatic code generation; formal methods

1   引言(Introduction)

在各種开发方法中,模型驱动设计(Model-Driven Design)因其合理与高效已被工业界广泛运用[1-2]。在模型驱动设计框架下,先对系统进行建模,随后通过大量的分析与验证对该模型进行更新与修改,这就使得在设计的早期阶段就可以对错误进行检测和纠正。统一建模语言(UML)就是该开发过程中最常用的一种可视化建模工具,它提供了很多不同类型的图表,分别从不同的视点去建模系统,比如数据、行为、交互、组件架构等机制。

当开发人员用UML完成对系统的建模后,需要进一步将抽象模型转换为更具体的模型,并最终转换为可执行代码。但在过去的大部分转换过程中,由于没有完整的自动化方法,导致整个过程的成本较高,并且其中的手工部分因为缺乏形式化方法的支撑,也会造成整个过程容易出错[3]。……

登录APP查看全文