从图/UML/可视化表示生成Python代码 [英] Generating Python code from a diagram / UML / visual representation

查看:85
本文介绍了从图/UML/可视化表示生成Python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Python类,可以用某种可视化工具来管理.每个类都有一些可以执行操作的方法(同时也可以接受参数或返回值或其他类实例).

让我们说这些类是人",帽子"和手表".现在,假设人员"具有方法 getName() putOn(object).

从代码的角度来看,将手表"或帽子"附加到人"(鉴于我刚刚提到的类)将很容易:

  person = Person()如果person.getName()=="Fred":手表=手表()person.putOn(手表)别的:帽子=帽子()person.putOn(帽子) 

但是,如果我希望能够绘制"类实例之间的这种交互方式呢?

想象一下一个类似于UML的可视化工具,该工具将允许我通过从类"的面板中拖放这些类的实例"来表示"代码,然后生成与该类行为完全相同的代码./p>

有没有我可以使用的库来乞求实现类似的东西?也许甚至还有一些有关该主题的文献?

解决方案

您不必要求从生成代码(图表是标准化的图片,其中显示了一部分您需要一个工具从活动生成代码(可以在图表中显示).

作为状态机,活动是一种行为,可以表示操作的定义,例如与交互相反(可以通过序列图显示)

在您的代码中,获取新创建的 Person 的名称似乎是人为的,该名称在创建时未在参数中给出.假设实例是通过输入参数 person 接收的,表示您的代码的活动可以是:

其中绿色的动作是调用操作动作(被调用的操作命名为要清除),蓝色的是创建对象动作(其名称表示班级要明确).

另外,为了使图表更清晰, pin 名称"实际上具有方向 return

从该活动生成Python代码并没有什么不对的地方,请注意还可以帮助您将动作定义为不透明的形式,以便您可以直接放置Python代码.

我知道建模者会这样做吗?不,抱歉,甚至我想通过插件 BoUML 中进行操作我以同样的方式制作了状态机生成器(生成C ++代码),但没有人要求.所以,就这样做吗?

I have some Python classes that I pretend to manage with a visual tool of some sort. Each class has some methods that can perform operations (while also accepting arguments or returning values or other class instances).

Let's say that the classes are "Person", "Hat" and "Handwatch". Now, let's say that "Person" has the methods getName() and putOn(object).

From a code point of view, attaching a "handwatch" or a "hat" to a "person" (given the classes I just mentioned) would be as easy as:

person = Person()
if person.getName() == "Fred":
    handwatch = Handwatch()
    person.putOn(handwatch)
else:
    hat = Hat()
    person.putOn(hat)

But what if I wanted to be able to "draw" that sort of interaction between instances of my classes?

Imagine a visual UML-like tool that would let me "represent" code by dragging from a palette of "classes" and dropping "instances" of those classes, and that then would generate code that would behave exactly like that.

Are there any libraries that I could use in order to even begging implementing something like that? Or maybe even some literature on the subject?

解决方案

You cannot require to generate code from a diagram (a diagram is a normalized picture showing a part of the model), you are requiring a tool generating code from an activity (which can be shown in diagram(s)).

As a state machine an activity is a behavior and can represent the definition of an operation, contrarily to an interaction for instance (may be shown through a sequence diagram)

In your code it seems artificial to get the name of a newly created Person whose name is not given in parameter at the creation. Let say that instance is received through the input parameter person and the activity representing your code can be :

where the actions in green are call operation actions (there are named by the called operation to be clear), and the blue are create object actions (whose name indicates the class to be clear).

Also for the clarity of the diagram the pin 'name' has in fact the direction return etc

There is nothing against generating Python code from that activity, note also to help the definition of an action can be an opaque form where you can directly put Python code.

Do I know a modeler doing that ? no, sorry, even I imagined to do in BoUML through a plug-out in the same way I made a state machine generator (producing C++ code), but nobody asked for. So, just do it ?

这篇关于从图/UML/可视化表示生成Python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆