UML建模中的状态图及状态图建模原则示例摘要(转摘)

在学习Thinking in Patterns chapter 18: Complex system states中的StateMachine的前半部分时(TIPatterns.htm#_Toc41169779),与我原来看那本System Analysis and Design中文译本中的UML建模中的状态图作了一下比较。发现二者有比较大的区别,故把状态图的有关知识再复习了一下。

下面是我在网上搜索到的一篇讲述UML状态图的文章,其中对状态图的基本定义和它在实际应用中的示例和原则都作了详细的阐述。不过比较长,而且是翻译过来的,很不好理解。尤其是前半部分讲基础概念的,更是模模糊糊的。我根据自己的需要,把上面的内容摘录了一些提纲性的东西备用。

一、基础部分

  状态图(Statechart Diagram)是描述一个实体基于事件反应的动态行为,显示了该实体如何根据当前所处的状态对不同的时间做出反应的。通常我们创建一个UML状态图是为了以下的研究目的:研究类、角色、子系统、或组件的复杂行为。

 

  状态机由状态组成,各状态由转移链接在一起。状态是对象执行某项活动或等待某个事件时的条件。转移是两个状态之间的关系,它由某个事件触发,然后执行特定的操作或评估并导致特定的结束状态。图 1 描绘了状态机的各种元素。

  状态机的要素:(图 1:状态机符号。)

  状态的要素:


名称:            将一个状态与其他状态区分开来的文本字符串;状态也可能是匿名的,这表示它没有名称。

进入/退出操作:    在进入和退出状态时所执行的操作。

内部转移:        在不使状态发生变更的情况下进行的转移。

子状态:          状态的嵌套结构,包括不相连的(依次处于活动状态的)或并行的(同时处于活动状态的)子状态。

延迟的事件:      未在该状态中处理但被延迟处理(即列队等待由另一个状态中的对象来处理)的一系列事件。

  转移的要素:


源状态:            转移所影响的状态;如果对象处于源状态,当对象收到转移的触发事件并且满足警戒条件(如果有)时,就可能会触发输出转移。

事件触发器:        使转移满足触发条件的事件。当处于源状态的对象收到该事件时(假设已满足其警戒条件),就可能会触发转移。

警戒条件:          一种布尔表达式。在接收到事件触发器而触发转移时,将对该表达式求值;如果该表达式求值结果为 True,则说明转移符合触发条件;如果该表达式求值结果为 False,则不触发转移。如果没有其他转移可以由同一事件来触发,该事件就将被丢弃。

操作:              可执行的、不可分割的计算过程,该计算可能直接作用于拥有状态机的对象,也可能间接作用于该对象可见的其他对象。

目标状态:          在完成转移后被激活的状态。

二、应用示例部分(结合示例讲了画状态图的一些准则):

  我觉得文中的这个示例太好了,值得经常看看。

1、通用准则

  1.1)、当行为的改变和状态有关时才创建状态图

  敏捷建模( AM) ( Ambler 2002)的原则--最大化项目干系人的投资--建议你只有当模型能够提供正面价值的时候才创建模型。

   

图⒈班级注册的一个UML状态图。

  1.2)、把初始状态放置在左上角。

  1.3)、把最终状态放置在右下角。

2、状态指南

  状态是一个实体的行为模式的某个阶段。 状态的表示是通过实体的属性值。

  2.1)、状态名称要简单但应具有描述性。

  2.2)、避免"黑洞"状态。

  2.3)、避免"奇迹"状态。

3、子状态建模指南

  3.1)、为复杂的目标建模子状态。

图⒉Seminar的完整生命周期

  3.2)、把通用的子状态变换放在一起

  3.3)、为复杂的实体创建一个分层的状态图

图⒊Seminar的高阶状态图。

  3.4)、最高阶的状态图总有初始态和最终态

4、变换和动作

  变换是从一种状态到另一种状态的序列,它可能是通过一个事件触发的。

  4.1)、用实现语言的命名规则命名软件动作

  4.2)、只有对所有的入口变换都合适时才注明入口动作

  4.3)、只有对所有的出口变换适合时才注明出口动作

  4.4)、出口动作,用exit/标记来表示,工作方式类似于入口动作。

  4.5)、只有当你想终止并再进入该状态时才建模递归变换

  4.6)、用过去式命名转换事件

  4.7)、把转换标记放在接近源状态的地方

  4.8)、以转换方向为基础放置变换标记

    4.9)、为了更易于判断哪个标记和变换是一起的,按照如下的规则来放置变换标记:

      4.9.1)、在变换线条上的从左到右。

      4.9.2)、在变换线条下的从右到左。

      4.9.3)、变换线条右边的往下。

      4.9.4)、变换线条左边的往上。

5、警戒点

  一个警戒点是为了穿过一个转换而必须为真的一个条件。

  5.1)、警戒点不应该重叠

  5.2)、为可视化的定位警戒点而引入接合点。

  5.3)、警戒点不必配套

  5.4)、一致的命名警戒点

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

                          摘录完毕

Apollo for Eclipse 1.0 Released(Eclipse的UML建模插件)(转)

转自: Gentleware Newsletter(因为他们的产品起源于ArgoUML,所以我对他们有些关注,也可以练习英语:))

这封邮件讲的是Gentleware公司的Eclipse的UML建模插件Apollo正式版发布。

有几个新闻点可以注意一下:

1、有30天的免费试用期

2、他们加入了Eclipse基金会

3、有无版权限制的版本提供,但是没有模型输出选项

4、Poseidon for UML Version 5 在年底前发行

邮件正文:

 Gentleware Newsletter

Some spam filters and email servers may block all or part of newsletters or may require sender verification. To be sure that you receive the complete newsletter with no delay, please add the email address 'newsletter@gentleware.com' to your address book.

 

Apollo for Eclipse 1.0 Released

Dear Poseidon User,

It's a new age here at Gentleware, and this is the very last newsletter that will be addressed only to Poseidon users, lest we leave out our dear new Apollo users. That's right, the wait is over... Apollo for Eclipse, the newest modeling tool from Gentleware, has been launched!

Read on to find out more...

»  Apollo 1.0 ==>

»  Free 30-Day Trial =>

»  New Licensing =>

»  Eclipse Foundation =>

»  Poseidon 5.0 =>

http://www.gentleware.com/

Design element: 4 blue boxes

 

Apollo for Eclipse 1.0 - Official Release

Apollo for Eclipse is a modeling tool for programmers and developers who want to flexibly combine the advantages of visual modeling using UML with Java programming. Fully synchronized roundtrip engineering employs the latest releases of UML 2.1 and Java 5 to provide an instant visualization of any existing Java code through UML class diagrams, and likewise propagate changes to the UML model throughout the code.

The tool fully integrates into the Eclipse environment, which makes it easy for developers to view code as models, and vice versa.

Features include:

    * Forward, reverse, and roundtrip engineering

    * Support for Java 5

    * Support for UML 2.1

    * Superior class diagram handling

    * Available as a stand-alone Rich Client Platform or as an extension to Eclipse

»  Download Apollo for Eclipse version 1.0 =>

Design element: 4 blue boxes

 

Apollo for Eclipse 30 Day Trial - No Obligation

Try all of the features of Apollo for Eclipse free for 30 days. Sign up for a our special Trial Package, you can cancel completely cost-free and obligation-free at any time during the first 30 days. More information is available from our website.

»  Read details of the trial offer =>

Design element: 4 blue boxes

 

New Licensing Structure

Apollo for Eclipse licenses are available to rent, much like web services. You can rent a license for a single period or on a continuing subscription basis. This licensing model allows professional organizations to deploy Apollo for Eclipse as they need to, and for a lower cost.

An unlicensed version of Apollo for Eclipse is also available, just download and start working. Export options are disabled in the unlicensed version.

This licensing structure will apply to the Community Edition of Poseidon for UML, beginning with the release of version 5.

»  Find out more about Apollo for Eclipse licensing =>

Design element: 4 blue boxes

 

Gentleware Joins Eclipse Foundation

Gentleware has selected the Eclipse IDE for both in-house development and as a platform for Apollo for Eclipse and future products. To support this effort, Gentleware has joined the Eclipse Foundation as an Add-In provider.

»  Read more about Gentleware in the Eclipse Foundation =>

Design element: 4 blue boxes

 

Poseidon for UML Version 5 - Coming Soon

The addition of Apollo for Eclipse to the offerings of Gentleware doesn't mean the end of Poseidon for UML. A new major release of Poseidon for UML is coming before the end of the year, so keep watching for upcoming announcements.

Design element: 4 blue boxes

 

Best regards,

Marko Boger

CEO

Gentleware Logo

 

Design element: 4 blue boxes

Contact   Terms of Use   Privacy Policy

© 2000-2006 by Gentleware AG

If you no longer wish to receive these emails, please reply to this message with "Unsubscribe" in the subject line or simply click on the following link: Unsubscribe

Gentleware AG

Ludwigstrasse 12

20357 Hamburg

Germany

Read the VerticalResponse marketing policy.

一封来自Gentleware的CEO的信

Gentleware的Poseidon for UML建模工具起源于开源UML建模工具:ArgoUML0.9。现在的Gentleware公司的CEO就是ArgoUML的项目拥有者之一:Marko Boger。你可以在ArgoUML的主页上看到。

从下面这封信中,我感到了起源于开源软件的商业软件的强大活力(他也提供共享版本,不过功能很受限,可以作为学习之用);反之,看他的开源前辈ArgoUML,可以说是鲜有使用者,也许在我不了解其中具体情况下下一个不成熟的结论:半死不活。

这是为什么?难道ArgoUML终究不能成为一个像其他开源工具如:ant、eclispe、Tomcat、Linux等一样的流行工具?难道说ArgoUML的存在就是因为有了它的商业分支版本"Poseidon for UML"? 难道ArgoUML就是”认知建模“的一个试验品(它的认知建模好像是可以智能的分析模型的合理程度,还可以根据知识库纠正一些问题或提出建议)?在我用来,它的认知建模好像没有多大用处(起源于它的Poseidon for UML就去掉了这个特性)。搞不懂,不过对我这个UML的学习者来说,用ArgoUML来画画图,理理思路还是够用了。

从下面这封订阅来自Poseidon for UML的信中可以大概知道:

1、它要发集成在eclipse中的Apollo for Eclipse建模插件了;

2、对于发行采用基于Web Service模型的新许可形式了,购买、延续、改变许可将更加自动化;

3、Apollo for Eclipse和 Poseidon for UML同时存在,定位不同,且都有供学习用的共享版本。

下面是这封电子邮件的原文,可以以此来看软件业的趋势、开源软件的命运和运作,以及这些给普通软件用户带来的影响。

××××××××××××××××××××××××××××××××××××××××××××××××××

A Letter to You: From Gentleware's CEO

Dear Loyal Poseidon User,

With this letter, I'd like to inform you about a series of major events and changes that will be occurring in the next few months. Please bear with me; I am certain that you will find this message to be worthwhile reading. You are part of the cherished user base that Gentleware has built up over the past 6 years. As such, you are one of the first to be informed.

We are proud and honored to have such a large and loyal audience, and we have been working extremely hard to fulfill your expectations. Our user community has grown so much that the range of users now extends beyond the scope of our previous tool lineup, and the range of expectations has correspondingly grown. Many users, especially those working in the later development phases who want to review and modify models and code simultaneously, expressed the need for a tight integration into Eclipse. Poseidon for UML is built on Swing while Eclipse is built in SWT, so an integration can only go so far. For a clean integration we had to start from scratch. And so we did.

   

   

Apollo for Eclipse

We are pleased to present our newest tool, Apollo for Eclipse, which will be released in the coming weeks.

Built from the ground up as an extension to Eclipse, Apollo for Eclipse makes use of all of the relevant modules from the Eclipse Modeling Project. Most notably, it uses EMF (Eclipse Modeling Framework) and its instantiation for UML, the UML2 project, as a repository. This provides a standard API and saving format and makes it easy to connect other tools like generators or transformation engines to it.

It is our understanding that this is the first professional modeling tool built using GMF. GMF is a framework to create graphical editors in Eclipse and was released just this summer. We regard it as the best technology available to build modeling tools. It provides a standardized yet adaptable user interface that is well adapted to Eclipse, and it provides us with great flexibility to quickly create editors for standard or domain specific notations.

With the initial release of Apollo for Eclipse, we have focused specifically on the class diagram and a clean, robust, and scalable roundtrip mechanism for Java 5 and UML 2.1. More details will be forthcoming in the next newsletter.

   

   

Poseidon for UML

This isn't to say that Poseidon for UML is going away. Poseidon for UML continues to be the best option on the market for analysts and designers who don't work as extensively with Eclipse. In just a short while, we will be bringing out version 5.0 of Poseidon for UML. As with every release, it has a number of important and interesting updates. But I have to say that this release is really special to me. I feel that after 6 years of development we have now reached what we initially started our quest for: namely, to provide the most usable UML modeling tool available. We will provide you with the specific details of the release in a separate newsletter.

   

   

New Licensing Based on the Web Service Model

The software industry is fast paced and changes quickly. With the ubiquity of the internet and with flexible download and update mechanisms provided by the Eclipse platform, software products today have much of the character of a web service. In response, we have adapted our pricing model to reflect this. We have worked hard to find a model that suits the wide variety of our users, from students with minimal budgets, to occasional users with high demands, and on to large corporations with long-term usage scenarios.

We are introducing a rental and subscription model for our new product, which may be familiar to you from other Internet services. Base functionality of the tool is available for free; extended functionality including all exporting capabilities requires a license.

This rental and subscription license model will apply to the Apollo for Eclipse product. Likewise, we will implement it for the Poseidon for UML Community Edition starting with the release of version 5.0. This solution eliminates the conflicts many users have had with our current license terms, which restricts how the Community Edition may be used through the stated condition, "free for non-commercial use".

The Community Edition was originally intended to be a learning tool for those just starting out in UML. It has become an important tool for analysts and designers who depend on Poseidon for UML to communicate with various stakeholders throughout the development lifecycle. The new licensing agreement now allows these users to take advantage of the many powerful features of Poseidon for UML for the nominal charge of only 5 Euros per month.

The unregistered version of the Poseidon for UML Community Edition can still be used for learning UML; all of the features needed to work alongside a textbook or tutorial remain available. Users can open and edit models to explore code and diagrams, but all export features such as saving, copying to the Windows clipboard, and printing are only available in the registered version.

   

   

Options

The first option is to rent a license for a fixed period of time; specifically, for a month, a quarter, or a year. The fee for one month is 5 EUR or 6 USD, longer periods are further discounted. You always maintain the option, but are not obligated, to renew the license after it expires.

The alternative option is to subscribe to the service and thus be assured of continuous access to the most current version. Updates and registration are automatically conducted as soon as you are online. You can decide on the automatically-renewing payment periods that best suit your needs, again with the choices of a month, a quarter, or a year. You can cancel the subscription easily and transparently at any time.

Students in accredited programs have the additional option to purchase the full Professional Edition at a deep discount, and site licensing for universities remains as an economical alternative. Current Community Edition users will be able to continue to operate under the old license agreement until the beginning of 2007.

   

   

Your Opportunity to Try Apollo for Eclipse

Poseidon for UML and Apollo for Eclipse address two very different types of usages. Whereas Poseidon for UML provides the full power of UML 2 during analysis and design phase, Apollo for Eclipse addresses the needs of developers and programmers. We realise that many of you indeed have both use cases, but at different times. To accomodate our users, soon we will be sending out keys for Apollo for Eclipse to premium edition Poseidon for UML customers for a limited introductory period, so that you can have full access and can immediately evaluate our new offering.

So stay tuned, there are a lot of compelling developments coming in the next few weeks. We hope that you are as excited as we are.

Best regards,

your Marko Boger

CEO, Gentleware AG

   

   

contact      impressum      privacy policy      sitemap      print version

© 2000 - 2006 Gentleware AG

If you no longer wish to receive these emails, please reply to this message with "Unsubscribe" in the subject line or simply click on the following link: Unsubscribe

Gentleware AG

Ludwigstrasse 12

20357 Hamburg

Germany

Read the VerticalResponse marketing policy.

绘制UML活动图的步骤和要点(转帖)

绘制UML活动图的步骤和要点,转自:http://www.yesky.com/427/1794427.shtml

UML 活动图记录了单个操作或方法的逻辑,单个用户案例,或者单个业务流程的逻辑。要创建一个 UML 活动图,您需要反复执行下列步骤。

  第一步,定义活动图的范围首先应该定义您要对什么建模。单个用户案例力?一个用户案例的一部分?一个包含多个用户案例的商务流程?一个类的单个方法?一旦您定义了您所作图的范围,您应该在其顶部,用一个标注添加标签,指明该图的标题和唯一的标示符。您有可能也想要包括该图的时间甚至作者名。

  第二步,添加起始和结束点每个活动图有一个起始点和结束点,因此您也要马上添加它们。在 《UML 精粹》(UML Distilled) (参见参考资料),Fowler 和 Scott 认为结束点是可选的。有时候一个活动只是一个简单的结束,如果是这种情况,指明其唯一的转变是到一个结束点也是无害的。这样,当其他人阅读您的图时,他或她知道您已经考虑了如何退出这些活动。

  第三步,添加活动如果您正对一个用户案例建模,对每个角色(actor)所发出的主要步骤引入一个活动(该活动可能包括起始步骤,加上对起始步骤系统响应的任何步骤)。如果您正对一个高层的商务流程建模,对每个主要流程引入一个活动,通常为一个用户案例或用户案例包。最后,如果您正对一个方法建模,那么对此引入一个活动是很常见的。

  第四步,添加活动间的转变我的风格总是应该退出一个活动,即使它是转变到一个结束点。一旦一个活动有多个转变时,您必需对每个转变加以相应标示。

  第五步,添加决策点有时候,您所建模的逻辑需要做出一个决策。有可能是需要检查某些事务或比较某些事务。要注意的是,使用决策点是可选的。

  第六步,找出可并行活动之处当两个活动间没有直接的联系,而且它们都必需在第三个活动开始前结束,那它们是可以并行运行的。

关于用ArgoUML和AndroMDA协作工作的问题及答案(转)

(问题,转自:argouml用户邮件列表)

Date: Wed, 15 Mar 2006 15:58:51 +0530

From: ashikali.abdulkhader@wipro.com  Add to Address Book  Add Mobile Alert 

To: users@argouml.tigris.org

Subject: RE: [argouml-users] How to assign an activity diagram to a controller class.

   

Yeah. It works fine now. !!!

Thank you all.

-Ashik

-----Original Message-----

From: Ludovic Maitre [mailto:ludovic.maitre@free.fr]

Sent: Wednesday, March 15, 2006 1:36 AM

To: users@argouml.tigris.org

Subject: Re: [argouml-users] How to assign an activity diagram to a

controller class.

Hi Dashing and Abdulkhader,

See issue http://argouml.tigris.org/issues/show_bug.cgi?id=4005 for

assigning the context of an activity diagram. Should this issue answer

to your question ?

Dashing Meng wrote:

> He,

> A interesting question,I am happy to hear any reply for it too.

>

> Dashing

>

> */ashikali.abdulkhader@wipro.com/* wrote:

>

>     Hi All,

>    

>     I am currently facing the following problem while building the

>     Online-Store application that comes with AndroMDA.

>    

>     My model is developed using ArgoUML. Currently I face two

>     inter-related problems in building the Online-Store model using

>     the Maven plug-in.

>

>     1) Initially I've created the Activity-Graph in the Use-case's

>     namespace. But there is no way in ArgoUML by which I can assign

>     the activity graph to a controller class (As it is there in

>     Magicdraw) for calling deferrable call events in action states.

>     Hence this resulted in Validation Error during model validation

>     process.

>

>     2) The solution provided is to create the activity graph in the

>     namespace of a Class. Hence I created the activity graph in the

>     controller class's namespace and now am getting the validation

>     error that says "A use case should have one and only one activity

>     graph associated with it".

>

>     Kindly help me how I should design my model in ArgoUML (Associate

>     an Activity Graph with a Controller Class as expected by

AndroMDA)

>     so that I would be able to integrate the model with AndroMDA for

>     code generation.

>    

>     -Ashik

>

------------------------------------------------------------------------

>     *From:* Dashing Meng [mailto:learndiary_dashing@yahoo.com]

>     *Sent:* Monday, March 13, 2006 4:51 PM

>     *To:* users@argouml.tigris.org

>     *Subject:* RE: [argouml-users] How to assign an activity diagram

>     to a controller class.

>

>     I think an activity graph can be in the namespace of a operation

>     of the class or a usecase's namespace.can't be in the namespace

of

>     a class.

>    

>     Dashing

>

>     */ashikali.abdulkhader@wipro.com/* wrote:

>

>         Dashing,

>        

>         Thanks for your information..

>        

>         In my case the activity graph is already in a use-case's

>         namespace.

>        

>         Now how do I map it to a class's namespace..Wouldn't it be

>         redundant.

>        

>         If my understanding is right the behavior is for a usecase

and

>         not for a class right?

>        

>         Pls corr ect me if I am wrong.

>        

>         Regards,

>         Ashik

>

------------------------------------------------------------------------

>         *From:* Dashing Meng [mailto:learndiary_dashing@yahoo.com]

>         *Sent:* Monday, March 13, 2006 4:32 PM

>         *To:* users@argouml.tigris.org

>         *Subject:* Re: [argouml-users] How to assign an activity

>         diagram to a controller class.

>

>         Draw the state graph under class's namespace. It is: click a

>         class at left side of window, then choose "create-> new

>         statechart diagram" on the menu.

>         It seems an operation can't be synchronized between the class

>         diagram and the statechart diagram in both two directions?I

>         don't know it very clear.

>        

>         Dashing

>

>         */ashikali.abdulkhader@wipro.com/* wrote:

>

>             Hi all,

>             Does ArgoUML has the feature of assigning a

state/activity

>             graph to a class so that action states can defer

>             operations to the class?< /DIV>

>             This is required for running my model built in AndroMDA.

>             Regards,

>             Ashik

答案:转自argouml问题跟踪系统:http://argouml.tigris.org/issues/long_list.cgi?issuelist=4005

Make activity graph context assignment easier

Issue #: 4005  Component: argouml  Version: 0.20  Platform: PC 

OS/Version: Windows XP  Status: STARTED  Issue type: ENHANCEMENT  Priority: P3 

Resolution:  Assigned to: rastaman  Reporter: waiyung 

Subcomponent: Diagrams  Target milestone:---     

URL:  

Summary: Make activity graph context assignment easier 

Status whiteboard:

Description: 

I am using the Argouml with Andromda extension.

One thing required by Andromda is to assign a controller class as the context of

an activity graph by adding a tag like these, as quote from Andromda's guide:

-----------

 Add a tagged value to the controller, pointing to the use-case, like this:

@andromda.presentation.controller.usecase=My UseCase  (the value is the name of

the use-case).

-----------

I noticed with or without setting this tag, the exported xmi file from argouml

has the following tag within the activity tag:

-----------

   <UML:StateMachine.context>

                    <UML:UseCase xmi.idref = '.:0000000000000EB9'/>

   </UML:StateMachine.context>

--------

where it references the Use Case.

Is there a way to change the context to point to the controller class?

Thanks,

wai yung------- Additional comments from Ludovic Maître Mon Feb 27 10:38:51 -0800 2006 -------

Hi Wai,

To assign an object as the context of an activty diagram i usually do the

following :

- create an use case

- create a class

- create an activity diagram for the use case

- select the activty GRAPH,

- in the property panel use the dropdown list named "Represented Modelelement"

to assign the context of the graph.

Is it what you want to do ?

 ------- Additional comments from Bob Tarling Mon Feb 27 12:11:28 -0800 2006 -------

Is it worth adding context menus to help with this?

Right click on diagram background or explorer element?------- Additional comments from wai yung Tue Feb 28 07:54:39 -0800 2006 -------

Yes. This is exactly what I want.

Thanks------- Additional comments from Ludovic Maître Tue Mar 14 14:07:23 -0800 2006 -------

*** Issue 4090 has been marked as a duplicate of this issue. ***

--------------------------------------------------------------------------------

AndroMDA 3.0 M3--开源的MDA方案即将可用(转帖)

现在的AndroMDA已经出到3.2了,这篇3.0 M3的作为收藏。

 

AndroMDA 3.0 M3--开源的MDA方案即将可用  (转自:http://www.chinaitpower.com/A/2005-03-01/148795.html)

 

作者:未知 时间:2005-03-01 12:12 出处:Blog 责编:chinaitpower 

 

              摘要:暂无

 

 

因为有些IDE不支持,一直没有完整留意UML的扩展机制,所以也就以为UML不很适合做MDA。比如生成Hibernate的hbm文件,一些属性的辅助属性比如lazy-load,应该放在Class图的哪里呢? 最近AndroMDA在TSS上发广告,介绍说AndroMDA 3.0 M3作为正式版前的最后一个MileStone已经推出。就连过去看了一下。原来除了StereoType,UML另有Tagged Value的机制,可以把一些属性附在类的方法和属性上。 AndroMDA的结构应该说比较开放和实际的 1.AndroMDA使用过程 1.程序员通过Poseidon or MagicDraw 绘制UML图并导出XMI 或者使用 Schema2XMI工具从数据库生成XMI 在绘制的过程中需要加入AndroMDA所需的StereoType和Table tag,column Tag等。 MagicDraw似乎比较难看,而Poseidon还提供AndroMDA的plug-in,什么功能还没细看。 2.用户通过Ant运行AndroMDA Ant脚本除了指明xmi文件外,另一个很重要的节点就是节点,指明了Hibernate,Spring所需的一切项目级资料比如生成目录,数据源名称等。 3.AndromMDA解释XMI为相对高层的概念,然后调用Cartridge的Velocity语法模板的生成目标代码文件。 目前提供EJB,Hibernate,Spring等几个Cartridge。 如果要扩展Cartridge,只需要按照文档所教的方法,从内到外进行各种层次的增加,修改和替换。 2.五个核心部件核心部件的设计代表了AndroMDA扩展的野心 1.Template Engines 目前使用Velocity作为模板语言,支持向其他语言的扩展。 2.MetaFascade 提供一个高层的Meta-Data访问API, 支持UML1.3、1.4、2.0等等语法的MOF model并可自行扩展。 3 Repositories 支持从XMI文件中读取MOF model,支持其他格式的扩展。 4.Cartridge 通过MetaFascade读取元模型,通过模板生成代码的核心。AndroMDA自带了Spring,Hibernate等Cartridge,也可自行扩展。 5.Translation-Libraries 把平台无关代码翻译成平台相关代码。比如Hibernate的getXXX()方法的HSQL语句,用者可以选择用Tagged Value写在模型里,也可以选择写成平台无关的OCL查询语言,然后用Query-Translation把它翻译成Hibernate HSQL,日后也可次翻译成EJB的EQL。 目前有Query和Valiations两个Library,亦可自行扩展。 3.AndroMDA的意义 AndroMDA带出的最重要的信息是,相对标准的,开源的MDA方案开始可用了,无数程序员不懈的代码自动生成的分散努力,有望纳入一个比较统一的框架内进行。 对比自己的简易版MDA方案: 1.模型的编写与维护 好处第一是, 以前的模型是自己制定的XML标准,现在是标准的UML语言,谁不想自己的东西标准化一点,谁不想被招安阿。 第二是模型可以使用图形化的工具维护模型了。 坏处也是,只能使用图形化工具维护模型了,没有了以前XML文件的文本级的简单。 2.代码的生成 大家暂时都是使用Velocity,只不过它有现成的Cartridge,估计还会不断增加,众人拾柴,比自己孤军奋战,一些大点的模板根本没法写(从经济学角度)好多了。 坏处就是以后修改扩展模板都要循规蹈矩,依足手续,比原来的随意扩展麻烦好多。 等他的正式版出来, 正好也是我们项目结束, 整理代码以作重用的好日子吧. 

 

ArgoUML的开发者向AndroMDA项目提交Argo与Andro组合的教材

"Tom Morris" <tfmorris@gmail.com>  Add to Address Book  Add Mobile Alert 

To: users@argouml.tigris.org

Date: Sat, 11 Mar 2006 18:45:43 -0500

Subject: [argouml-users] Instructions for using ArgoUML with AndroMDA tutorial

   

I've created a first draft of directions on how to use ArgoUML for the

AndroMDA "Getting started for Java" tutorial and the AndroMDA team has

included them as part of the tutorial.  You can access them from the

AndroMDA home page (http://www.andromda.org) by clicking on the link in

the

Documentation box on the left hand side.

The tutorial requires an AndroMDA 3.2 snapshot (3.2 is still under

development) and it doesn't cover any web stuff (Struts or JSF), but it

does

provide a very detailed step-by-step for those who are new to AndroMDA

and

want to be led through the initial learning phase.

If you find problems or have suggestions on ways to improve the

instructions, please send me mail and I'll get them incorporated.

Tom

UML在关系型数据库设计中的应用(转帖)

UML在关系型数据库设计中的应用 (转自:http://edu.sdinfo.net/74596379271364608/20030822/1194035.shtml)

发布时间: 08月22日 11:34

------------------------------------------------------------------------------------------------------ 1. 介绍

  许多人认为面向对象概念和关系型数据库相互不一致,并且不能结合。事实上完全相反!经过灵活的使用,一个关系型数据库能够为面向对象(OO)模型提供一套优秀的实现。同样的模型能够用来开发编程代码和关系型数据库结构。

  关系型数据库技术是意义深远的、强大的,但它比许多开发商使你相信的要难得多。单个表是简单易懂的、直观的。但由数以百计的表组成(这是常见的)的应用要彻底了解是相当困难的。这正是OO模型有用之处。 OO模型使你深入地、连贯地思考问题。

  OO模型提供一种问题的超结构(superstructure)的思考方式,然后该方式能够用关系型数据库的更低层的组成块来实现。

  本文章综合地讨论了关系型数据库技术,而不是集中于特定的产品上。我们将不讨论物理设计细节(例如存储分配和物理聚集),因为它们是依赖于产品的。

  用关系型数据库实现UML模型有两个方面:映射结构(第2节)和映射功能(第3节)。第4节注解了面向对象到关系型数据库的扩展。第5节总结本文章。

  2. 结构映射到表

  UML对象模型在本质上只是一个扩展的实体-关系(ER)模型 。使用设计数据库的ER模型的方式受到普遍接受,而我们以一种近似的但更强大的方式-使用UML对象模型。OO模型的主要优势在于编程和数据库的相同的模型工作。而且,作为考虑功能性的一种方式(第3节),我们强调OO模型的导航。这一节显示如何实现UML对象模型的主要构造。

  2.1 标识(identity)

  实现对象模型的第一步是处理标识。我们从定义几个术语开始。

  1)候选键(candidate key)是一个或多个属性的组合,它唯一地确定某个表里的记录。一个候选键里的属性集必须是最小化的;除非破坏唯一性,否则属性不能从候选键删除。候选键里的属性不能为空。

  2)主键(primary key)是一个特定地选定的候选键,用来优先地参考记录。

  3)外键(foreign key)是一个候选键的参考。外键必须包括每个要素属性的一个值,或者它必须全部为空。外键用来实现关联和一般化。

  正常地你应该为每个表定义一个主键,尽管偶尔有例外。我们强烈建议所有的外键都只指向主键而不是其它的候选键。

  定义主键有两种基本的方法:

  1)基于存在的标识。你应该为每个类表加一个对象标识符属性,并将它设为主键。每个关联表的主键包括一个或更多的相关类的标识符。基于存在的标识符有作为单独属性的优势,占位小且大小相同。只要你的关系型数据库管理系统(RDBMS)受支持,基于存在的标识符就没有性能的劣势。(多数RDBMS提供有效的基于存在的标识符的分配顺序号码。)唯一的劣势是基于存在的标识符在维护时内没有固有的意义。

  2)基于值的标识。一些真实世界的属性的组合确定了每个对象。基于值的标识有不同的优势。主键对于用户有固有的意义,容易进行调试和数据库维护。在另一面,基于值的主键很难改变。一个主键的改变需要传播到许多外键。一些对象没有自然的真实世界里的标识符。

  我们推荐你在超过30个类的RDBMS应用里使用基于存在的标识。基于存在和基于值的标识都是所有RDBMS应用的可行选项。

  2.2 域(属性类型)

  属性类型是UML术语,对应于数据库著作里的域的术语。比起直接用数据类型,域提升到更一致的设计,并便利了应用的定位。

  简单域很容易实现。你仅仅要定义相应的数据类型和大小。并且每个用了域的属性,你都必须为每个域约束加入一条SQL查询子句。简单域的一些例子是:名字(name),长字符(longString)和电话号码(phone-Number)。

  一个枚举域把一个属性限制在一系列的值里。枚举域比简单域实现起来更复杂,图表1显示了四个方法。

 

图表1:枚举的实现方法

 

  2.3类

  正常情况下,我们把每个类映射为一个表,每个属性映射为一个列。你可能因一个已产生的标识符(基于存在的标识符)、隐藏的关联(第2.4节)和通用鉴别器(第2.5节)需要一些另外的列。

  2.4关联

  现在我们讨论关联的实现。我们已经把我们的陈述分为建议的映射(我们正常使用的映射),可选的映射(我们偶尔使用的映射)和不鼓励的映射(我们遇到的应该避免的错误)。我们所有的例子都采用基于存在的标识。

  2.4.1 建议的映射

  多对多关联。用一个特别的表(图表2)来实现一个多对多关联。关联的主键是每个类的主键的合并。那些省略号(...)表示在模型里没有显示出来的属性。主键用黑体字体显示。

  一对多关联。把一个外键隐藏在“多”表(图表3)。角色名字成为外键属性名字的一部分。

  零或一对一关联。把外键隐藏在“零或一”表(图表4)。

  其它一对一关联。把外键隐藏在任一表里。

 

图表2:建议的实现:特殊的多对多关联表

 

图表3:建议的实现:隐藏的一对多关联

 

图表4:建议的实现:隐藏的零或一对一关联

  可选的映射 正常情况下我们使用建议的映射。但有些偶尔的情况,可选的映射更合适。

  特别的表。你也可以用特别的表(图表5)来实现一对多和一对一关联。特别的表给了你更统一的设计和更大的扩展性。无论如何,特别的关联表打碎了数据库,并增加了表的数量。此外,特别的关联表不能强迫一个更低的多重性限度为“一”。

 

图表5:可选的实现:特别的一对x关联表

  不鼓励的映射 我们已经注意到有些开发者选择有缺陷的映射。我们要注意这些映射以便可以避免。 合并。不要合并多个类,不要把关联强制成为一个单独的表(图表6)。这样减少了表的数量,但会干扰第三范式。

  两次隐藏一对一关联。不要把一个一对一关联隐藏两次,每次隐藏在一个类里(图表7)。这是多余的,无助于性能。

  相同的属性。不要用相同的属性来实现多个关联角色(图表8)。相同的属性使编程复杂,降低了扩展性。 泛化 现在我们讨论泛化。我们这里只论述单个继承。 建议的映射 最简单的方法是只映射超类和每个子类为一个表。所有的表共享一个共同的主键。应用必须执行子类的划分,因为RDBMS支持。(关于后者的详尽的描述,请参阅第4节。)

  特别的表。映射超类和每个子类为一个表(图表9)。所有的表共享一个共同的主键。鉴别器指出每个子类记录的适当的超类表。

 

图表9:建议的实现:分开的超类和子类表

  可选的映射 泛化有几个可选的映射。 消除。你可以优化除去那些除了主键外没有别的属性的类(图表10)。这样减少了表的数量,但提供更少的正规实现。

  减少超类属性。你可以除去超类表并把超类属性复制到每个子类(图表11)。这样可以有描述每个对象为一个表的优势。无论如何,它将引起数据库结构的冗余,你查找一个对象时可能需要搜索多个子类表。

  增加子类属性。作为第三个可选项,你可以除去子类表并存储所有的子类属性到超类表里(图表12)。这样用一个表描述每个对象,但干扰了第二范式。

 

图表10:可选的实现:消除不必的子类表

 

图表11:可选的实现:减少超类属性

  

 

图表12:可选的实现:增加子类属性

 

  参考完整性 一旦你已经建立了表,你就应该定义参考完整性动作来明确对象模型的意义。(不要使用SQL触发器来实现参考完整性!)如果你使用基于存在的标识,你将不需要传播更新的结果。我们建议以下对删除的参考完整性方针: 泛化。级联从泛化实现中产生的外键的删除。

  隐藏的关联,最小化多样性为零。正常地把外键设为空,但有时候你可能要禁止删除。

  隐藏的关联,最小化多样性为空。你可以级联一个删除的结果或者禁止该删除。

  关联表。正常地我们级联关联表里对记录的删除。可是,有时候我们禁止一个删除。

  我们已经简要地论及参考完整性,因为它是个高级话题。参考有更多的解释z和例子。 索引 实现数据库结构的最后的一步是加入索引来调整数据库性能。正常地,你应该为每个主键和候选键定义一个唯一的索引。(多数RDBMS作为SQL主键和候选键约束的副作用来建立唯一的索引。)你也应该为每个被主键或候选键所约束的外键建立一个索引。

  我们强调索引的重要性。外键和主键的索引使在对象模型里能快速地遍历是不容怀疑的。你必须包括这些索引否则你将使用户感到灰心。你应该在你的数据库开始设计阶段里加入索引,因为它们很容易加入并且也没有什么好理由推迟加入。

  数据库管理员(DBA)可能为经常请求的查询定义了额外的索引。DBA也可能采用产品相关的调整性能的机制。 范式 范式是关系型数据库设计的提高数据一致性的有效方法。我们的书3讨论了范式,但我们关于这个问题却言过甚微。我们将利用这篇文章的机会来澄清我们的观点。如果你不熟悉范式你可以跳过这节。我们的说明是针对关系型设计人员,他们正在尝试用面向对象适应他们原有的技能。

  范式是正确设计关系型数据库的精确的原则。同样地,它们与使用了什么开发技术是无关的 - 基于属性的设计、基于实体的设计、面向对象设计或其它什么。 过去使用基于属性设计的方法,开发人员不得不非常注意范式;范式提供了分组数据的根据。相反地,范式对于基于面向对象(或基于实体)的开发不是很重要。如果你采用OO方法并且你的模型经过很好的构思,那你就正在把数据组织成为有意义的单位,也在本质上满足了范式的规定。如果你愿意,你仍能够检查范式,但这样的检查是不必要的。 摘要 图表13总结了我们已经陈述的映射规则。这些映射规则的完整例子,包括一个UML对象模型,能够在这篇完整的扩展版本里找到(Adobe Acrobat PDF文件)。

 

图表13:推荐的映射规则的摘要

  

  把功能映射到SQL命令 对象模型为数据库应用提供三种主要的用途。 结构。对象模型指明数据库结构。我们已经在第二节探讨了这个方面。

  约束。对象模型也指明了能存储的数据上的重要的约束。相匹配的实现必须为迎合这些约束而努力。我们的映射规则的处理方法以及第二节里的参考完整性指出了许多约束。(本文没有论及的另外的UML构造,能获取更多的约束。)

  潜在估算。一个对象模型指明潜在估算;它是关于引起哪些查询和如何公式化的蓝图。第三节将简要地阐明第三个目的。

  对象模型不仅仅是被动的数据结构,相反它们能够帮助你思考一个应用的功能。你可以根据遍历一个对象模型说出它的许多功能。例如,根据我们对一个模型检查用例时的遍历,我们进行思索。这强调对象模型的估算能力对于RDBMS应用是特别重要的,因为遍历表达式可以直接映射到SQL代码。

  UML对象约束语言(Object Constraint Language,OCL)有助于表达遍历。点符号导航从对象到对象和对象到属性。方括号表示对象集合的过滤器。我们加入冒号(:)操作符来表示泛化的遍历;因为我们正常地用多个表来实现一个泛化继承,清楚的遍历很有用。

  图表14里的遍历表达式例子是基于我们创建的UML对象模型上的(请参阅本文的扩展版本(Adobe Acrobat PDF文件)),我们把它们映射为SQL代码。我们用冒号开始SQL编程变量。

 

图表14:对象模型遍历和SQL代码的例子

  到RDBMS的OO扩展 数据库团体对RDBMS的OO扩展有兴趣。产品和SQL标准正尝试加入到OO扩展里。我们将简要地陈述一下这个技术的方向。 抽象数据类型(ADT)。这是个好主意,扩展RDBMS的能力。开发商为这个技术使用了许多名字,例如Oracle cartridge和Informix data blades。ADT的缺点是它们把你紧紧绑在特定的一个开发商上;ADT的范畴超越了SQL标准。因此,你应该只在ADT的好处很明显的时候才使用。

  在关于ADT如何适合数据库开发的著作里有一些混乱。如果你使用OMT开发过程,你能够用属性实现简单域,用ADT实现复杂域。你仍应该用表实现类。 SQL3指针。最新的SQL标准的版本,SQL3,加入了作为一种数据类型的指针符号。显然,其意图是支持导航和面向对象。我们对于SQL3指针最友善的评语是,它们是嫁接的,是可以忽略的。更深入的批评是,指针在理论上是荒谬的,增加了复杂性,又没有扩展SQL的表达能力。CJ Date在上次的九月对象/关系型会议上雄辩地讨论了这一点。

  好了,那么我们冷淡地对待抽象数据类型和SQL指针的指责。但我们相当喜欢面向对象技术和关系型数据库。有两个为RDBMS的扩展可以使它们更容易用于OO技术。我们将很乐意看到RDBMS开发商把这些能力加入到他们的产品中。 扩展的参考完整性动作来支持泛化。当前的参考完整性机制是单向的。为了完全支持泛化,我们需要一个双向的机制。这样,一条超类记录就可以依赖一条子类记录。并且,一条子类记录就可以依赖一条超类记录。我们通过例子可以最好地解释这点。

  图表15摘录于我们的在3的财务案例学习。我们用资产超类来统一某些没有显示在摘录里的通用的数据和功能。一项资产可以是一只股票或股票特权。一只股票可以有许多它的股票特权。例如,IBM股票可以有许多达到价格和过期日期的写下的放或叫特权。

 

图表15:参考完整性和泛化的例子

  我们推荐的泛化实现是特别的表 - 映射该超类和每个子类为一个表。然后,我们就可以使用参考完整性使股票特权和股票的记录依赖于资产。一个资产记录的删除级联到相应的子类记录、股票特权或股票的删除上。我们也能够定义一个参考完整性动作,这样一个股票的删除就级联到关联的股票特权记录的删除。

  现在问题如下。如果我们删除的一项资产是一只股票,资产记录的删除级联到引起股票记录的删除。随后,股票记录的删除级联引起所有股票特权记录的删除。但现在参考完整性使我们失败了:一个股票特权记录的删除并不引起一项资产记录的删除。删除级联只能从超类走到子类。为了完全的行为,级联应该双向地走下去。

  当前有用的参考完整性的工作是做更多的编程(也即做更多的工作和风险更多故障)。在我们的用例学习的实现里,用户随时要删除一项是股票的资产,我们不得不书写额外的代码来首先检查关联股票特权的存在性,然后删除它们。 支持交叉表的记录划分。单独继承(泛化的最常见方式)的含义是一个超类的每个实例都是用多数只有一个子类来例示。现在的RDBMS不能容易地加强这个约束。例如,没有什么防止下面的情形。一只股票可以用ID18加入到资产表,用ID18加入到股票表,并且也可以用ID18加入到股票特权表。再一次地,我们为了确信行为的完整,不得不作额外的编程,而不是写一个简单的声明的约束 

  结论

  本文陈述了用关系型数据库实现UML模型的快速的概观。我们希望本文向你演示的技术是足够适宜的。一个训练有素的开发人员能够用关系型数据库准备一套优秀的OO模型的实现。如果你要关于实现机制的更多的细节,参考3有另外的信息,并且也覆盖了我们没有在这里讨论的一些高级模型建模结构。

文章出处:《中国电脑教育报》

记录一个好像还不错的uml模型到代码的code generator (AndroMDA

  一直知道ArgoUML在进行与androMDA的配套工作,昨天第一次上这个AndroMDA浏览了一下。好像还不错,以后可以实践一下。

  下面是它的定义:

What is AndroMDA?       

AndroMDA (pronounced "Andromeda") is an extensible generator framework that adheres to the Model Driven Architecture (MDA) paradigm. Models from UML tools will be transformed into deployable components for your favorite platform (J2EE, Spring, .NET). Unlike other MDA toolkits, AndroMDA comes with a host of ready-made cartridges that target today's development toolkits like Axis, jBPM, Struts, JSF, Spring and Hibernate. AndroMDA also contains a toolkit for building your own cartridges or customize existing ones - the meta cartridge. Using it, you can build a custom code generator using your favorite UML tool. 

  

Core Features       

AndroMDA currently comes with the following features:

Modular design: all major building blocks of AndroMDA are pluggable and can be exchanged to meet your needs

Support for major UML tools like MagicDraw, Poseidon, Enterprise Architect and more

Comes with the complete UML 1.4 metamodel (support for UML 2.0 is currently being developed) - alternatively, you can bring your own metamodel in MOF XMI and generate code from models based on it

Validates the input models using OCL constraints which are related to the metamodel classes. Comes with pre-configured constraints that protect you against the most common modeling mistakes - add your own project-specific constraints, too.

Model-to-model transformations help to raise abstraction level. Write your own transformations, currently in Java, or in any transformation language, e.g. the QVT-like Atlas Transformation Language (ATL), in the next major AndroMDA release.

Can generate any kind of text output using templates (source code, database scripts, web pages, O/R mapping configuration files, etc.) -  you teach it, AndroMDA does it!

Templates are based on well-known template engines. Currently, Velocity and FreeMarker are supported

Ready-to-use cartridges for common enterprise architectures (EJB, Spring, Hibernate, Struts, JSF, Axis, jBPM)

Support around the clock by team members around the globe: Measure the response time for questions in forum.andromda.org and be amazed by it! The forum already contains more than 10.000 articles.

 

  

Cartridges       

Very much like Eclipse, AndroMDA features a plug-in architecture. AndroMDA itself basically is a transformation engine. To support arbitrary target architectures, you can plug-in custom transformations. These transformations are packaged as so-called cartridges.

AndroMDA comes with a host of ready-to-use cartridges such as:

Spring

EJB 2 / 3

Webservices

Hibernate

Struts

JSF

Java

XSD

You can also write your own cartridge to support your own architecture or framework. AndroMDA can produce output for any architecture and computer language you might imagine. Courses for cartridge writing are available at AndroMDA.com.

 

 

 

反映给argouml的三个bug不能在0.20版本解决

  今天下午,花了1个小时收邮件,主要看了这段时间积累的argouml邮件列表里的邮件,其中三封邮件告知我提交的三个bug没有在0.20版本中得到解决。看来,argouml小组目前着重在argouml基础构架的改革,而对这些应用性的问题还没有来得及去做。这三个问题分别是:

1、  [Issue 3836] Wrong fill color for states  Sat Jan 28, 2006 2k

http://argouml.tigris.org/issues/show_bug.cgi?id=3836

2、 [Issue 3777] import description is error in an ArgoUML generated *.java file  Sat Jan 28, 2006 2k

http://argouml.tigris.org/issues/show_bug.cgi?id=3777

3、 [Issue 3356] Multiplicity not preserved in roundtrip engineering 

http://argouml.tigris.org/issues/show_bug.cgi?id=3356