模型驱动的开发:什么是转换? [英] Model-driven development: What is a transform?

查看:226
本文介绍了模型驱动的开发:什么是转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,模型驱动开发(MDD)可以实现自动化,从而可以通过应用转换从相应的模型自动生成程序/模型.

我对转换的全部了解是,转换是存储开发人员特定于平台的专业知识的某种方式.

但是什么是转换?

解决方案

A (程序) transformation 是给定程序表示实例并计算另一个实例的函数.

程序表示可以是任意的,但通常是抽象语法树(AST)或图形(例如UML);您甚至可以包含字节码作为程序表示.像数学函数一样,转换可以是部分的"(也就是说,只能在某些[可能复杂的]条件下工作).

我个人喜欢使用术语 transform 来指代函数本身,而使用 transformation 来指代应用变换以获得新表示形式的行为或结果. /p>

通常,(全局)程序转换可能会影响整个表示形式,即使它很大,但通常单个转换只修改一小部分,而大部分程序表示都将保持不变.抽象来说, 整个程序表示实例由转换处理,以生成另一个全新的程序表示实例.由于制图表达实例往往很大,因此通常可以通过使转换简单地修改现有的制图表达实例来实现. 您可以将这种小的"转换视为具有附加参数的参数,这些参数将它们集中在将对其进行更改的表示形式的特定部分上.

与数学函数一样,转换构成了更大的"转换(由于条件也构成了部分转换).通常,您编写一组转换的 来完全转换一个程序表示形式,因为没有一个转换可以一步完成整个表示形式实例的处理.可以组合它们的事实使您可以编写许多可以共同实现目标的小"转换,因此您在语义转换中获得了一种模块化,这就是为什么人们喜欢程序转换的想法.

就像数学函数一样,您可以通过编写过程代码来实现这种转换.这样的代码检查原始模型的各个部分,并在运行时对模型进行更改,但这通常很尴尬.

因此,此类转换通常以所谓的声明性"形式编写,如

实际上,单个转换仅适用于表示中的特定位置,并且它们的应用顺序(组成")很重要.为了解决这个问题,(程序)转换工具通常提供一种元程序"来控制焦点和规则应用顺序的方法.

这些想法适用于所谓的模型驱动的开发",这只是应用于可以说是高级模型的转换,以生成低级代码,或将低级代码转换为其他低级代码.您甚至可以使用这些想法来构建反向工程工具,例如,将低级代码映射到某个抽象模型.我们的 DMS软件再造工具包是一种程序转换工具,具有程序转换和源到源的重写,用于所有这些目的.

As I understand it, model-driven development (MDD) allows automation whereby programs/models are automatically generated from their corresponding models via the application of transformations.

All I know about transformations is that they are some way of storing a developer's platform-specific expertise.

But what exactly is a transformation?

解决方案

A (program) transformation is a function that given a program representation instance, computes another.

The program representation can be arbitrary, but is often an abstract syntax tree (AST) or a graph (e.g., UML); you can even include byte-code as a program representation. Like mathematical functions, transformations can be "partial" (that is, only work under some [possibly complicated] conditions).

I personally like the terminology transform to refer to the function itself, and transformation to refer to the act or result of applying the transform to get a new representation.

In general, a (global) program transformation may affect the entire representation even if it is huge, but typically individual transformations only modify a small part leaving most of the program representation alone. Abstractly, the entire program representation instance is processed by the transformation to produce another entirely new program representation instance. Since representation instances tend to be big, this is often implemented by having the transformation simply modify the existing representation instance. Such "small" transforms you can think of as having additional parameters that focus them on the specific part of the representation to which they will make a change.

Like mathematical functions, transformations compose to produce "bigger" transformations (that are also partial, as the conditions compose too). Usually you write a set of transformations to transform a program representation in its entirety, since no one transformation will process the entire representation instance in one step. The fact that you can compose them allows you to write lots of "little" transformations which collectively achieve your purpose, so you get a kind of modularity in the semantic translation, which is why people like the idea of program transformations.

Like mathematical functions, you can implement such transformations by writing procedural code. Such code inspects bits of the original model, and produce changes to the model as they run, but this is generally awkward.

So such transformations are instead often written in a so-called "declarative" form as rules which contain a pairs of patterns and a condition. Each rule is interpreted as, "if you see the left side pattern, and the condition matches, then change the program representation to match the right side pattern". Pattern variables allow the pattern to designate chunks of the original program representation to pass through the transformation untouched (normally to be processed by some other transformation). While these rules are called "declarative" (because they don't look like conventional code), they just represent some equivalent functions and so are not declarative in the intended sense. Rules tend to be a lot more readable than the equivalent procedural code, often because the patterns are written in the surface syntax of the source and target representations.

As a practical matter, individual transformations only apply to particular places in the representation, and the order in which they are applied ("compose") matters. To handle this, (program) transformation tools often provide a way to "metaprogram" to control the point of focus and the rule application order.

These ideas apply to so-called "model-driven development" which is just transformations applied to an arguably high-level model to generate low-level code, or to transform low-level code to other low-level code. You can even use these ideas to build reverse-engineering tools, e.g., map low-level code to some abstract model. Our DMS Software Reengineering Toolkit is a program transformation tool, have both procedural transforms and source-to-source rewrites, used for all of those purposes.

这篇关于模型驱动的开发:什么是转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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