`
yanghuidang
  • 浏览: 958119 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

(精品技术文摘)UML Stub Code and ASDocs(使用UML进行AS3程序设计) by Derrick Grigg

阅读更多

UML, Stub Code and ASDocs

这篇文章主要介绍了如何使用EA(Enterprise Architect)来展开基于UML的ActionScript3程序设计。 比较出色的地方在于对于EA中与AS3语法不相符的地方进行了修改,使得其可以直接从UML生成完全可编译的AS3代码,着实牛叉!

I have recently started using Enterprise Architect (EA) for creating UML diagrams for Actionscript and Flex projects. This is an outstanding product that is reducing my development time and helping me to create self documenting code following AsDoc formatting rules. If you have never created a UML diagram or used UML software, the concept can seem a little overwhelming but let me assure you, your time spent learning how to do so will be time very well spent.

In it's simplest form UML software allows a person to visually layout and architect a project before ever doing any actual coding. You can create your classes, document the properties and functions you intend to use, organize them and relate them (for either implementing or extending). At this point you are probably wondering why you would want to do that when you could just fire up your IDE of choice and start coding. Before I started using Enterprise Architect I only had one really good reason, it makes you think through the solution and plan before you start coding, so you can attack the project with a well defined plan. Now I have another reason, that I think is just as important as the first, EA can generate all your UML'd classes in either AS2 or AS3 in ASDoc friendly format. All your stub code is generated in seconds, perfectly formatted and compilable. This is an absolutely huge time and effort saver. By using UML you can create a well structured plan for your project and using the code generation in EA allows you to export all that planning effort into perfectly formatted Actionscript. I have created a sample project to demonstrate just how nicely this solution works and hopefully show why you may want to consider this approach for your projects. I will walk you through how to create a simple UML diagram in EA, how to export the diagram into AS3 files, and how to run the AS3 code through ASDoc to create project documentation.

You can download all my source files for this sample here.

Step 1 - Configure EA for Actionscript projects

这一段主要介绍了如何对EA进行设定,可以更好的在其中展开基于UML的AS3程序设计。

Download the trial version of Enterprise Architect. Once you have it installed a few adustments need to be made. First, select the 'Tools/Options' menu and click the 'Source Code Engineering' node, set the 'Default Language for Code Generation' to 'Actionscript'. Click on the 'Actionscript' node and set the 'Default Version' to whichever AS version you are working in. Second, the templates that generate the AS code need some tweaks (just a few minor things that EA appears to have missed). You have two options, import the template updates I created or do it manually. To import my adjustements, download this file, unzip it, in EA, open the 'Tools' menu and select the 'Import Reference Data' item. Browse to the 'actionscript_code_templates.xml' file, select and open it, select the 'Actionscript_Code_Template' and click 'Import'. To do it manualy open the 'Settings' menu and select the 'Code Generation Templates' item and then make these two changes.

  • Select the 'Class' template, change the entire section to
    %ImportSection%\n
    %ClassNotes%
    %ClassDeclaration%
    %ClassBody%
    This puts the import statements after the package declaration but before the class declaration in the as files.
  • Select the 'Operation Declaration' template, find this block of code (near the top)
    %PI=" "%
    %opStatic == "T" ? "static"%
    %if genOptActionscriptVersion=="3.0" and opTag:"namespace"!=""%
    %opTag:"namespace"%
    %else%
    %CONVERT_SCOPE(opScope)%
    %endIf%
    and change it to this
    %PI=" "%
    %opStatic == "T" ? "static"%
    %if genOptActionscriptVersion=="3.0" and opTag:"namespace"!=""%
    %opTag:"namespace"%
    %elseIf elemType=="Interface"%
    %else%
    %CONVERT_SCOPE(opScope)%
    %endIf%
    This ensures that functions in Interfaces can not be declared Public, Private etc, which will throw a compiler error.

Step 2 - Create a UML diagram

这一段主要介绍了如何在EA中进行UML设计,这个,看帮助会更清楚些。

Open EA and create a new project. In the project browser you can setup your package structure. For this sample I will keep it really simple and add a few packages 'com.dgrigg.vo', 'com.dgrigg.view'. The next step is creating the diagram. You can drag Class and Interface (to name a few) elements onto the diagram to begin creating your class structure. As you add new elements, you are prompted to enter the class properties. Enter information in the 'Notes' field to explain what the class is for. A few things to note when you are creating elements.

  • As you create Classes, Interfaces etc. and add Operations and Attributes (functions and properties) to each, be sure to enter a description in the 'Notes' field, this will get exported in your code and also be used by ASDocs.
  • When you create a new class you must create a constructor for it in the Operators list, for some reason EA does not do this for Actionscript projects.
  • If you add an Operator that has return value, be sure to enter a return line in the 'Initial Code' field on the 'Behavior' tab. This will set a 'default' return value in the code and allow ASDoc to properly execute and also not throw any compiler errors.
  • If the element you are working with needs to import '.as' files, right click on the element in the 'Project Browser', select 'Generate Code' and enter your import statements in the second 'Import(s)/Header(s)' field, click the 'Save' button.

When you are all done your diagram it will look something like this.

Step 3 - Generate the AS file

In the Project Browser right click on the 'com' folder, or whatever you root package folder is, and select 'Code Engineering/Generate Source Code'. Set the path you want to export to, check the 'Include all Child Packages' options, and click the 'Generate' button. Below is a sample of a generated AS file, straight from EA with no editing.

///////////////////////////////////////////////////////////
//  ProductList.as
//  Macromedia ActionScript Implementation of the Class ProductList
//  Generated by Enterprise Architect
//  Created on:      14-Sep-2006 5:08:46 PM
//  Original author: Derrick Grigg
///////////////////////////////////////////////////////////

package com.dgrigg.view
{
	import com.dgrigg.vo.ProductVO;
	import flash.text.TextField;
	import mx.controls.DataGrid;
	import flash.events.Event;
	import com.dgrigg.vo.ProductVO;
	import com.dgrigg.view.IView;

	/**
	 * Displays a DataGrid of products, lets the user select and view a product.
	 * 
	 * @see com.dgrigg.vo.ProductVO
	 * @author Derrick Grigg
	 * @version 1.0
	 * @updated 14-Sep-2006 7:38:22 PM
	 */
	public class ProductList implements IView
	{
	    /**
	     * displays the list of products
	     */
	    private var products_dg: DataGrid;
	    /**
	     * display the selected product's name
	     */
	    private var name_txt: TextField;
	    /**
	     * display the selected products' description
	     */
	    private var description_txt: TextField;
	    /**
	     * display the selected product's sku
	     */
	    private var sku_txt: TextField;

	    /**
	     * Constructor
	     */
	    public function ProductList()
	    {
	    }

	    /**
	     * add a product to the displayed product list
	     * 
	     * @param product    product to add to the product list
	     */
	    public function addProduct(product:ProductVO): Boolean
	    {
	    	return true;
	    }

	    public function getSelectedProduct(): ProductVO
	    {
	    	return new ProductVO();
	    }

	    /**
	     * handle the event that is triggered when a user selected a row in the data grid
	     * 
	     * @param event    event dispatched from DataGrid
	     */
	    public function handleSelectedProduct(event:Event): void
	    {
	    }

	}//end ProductList

}

Step 4 - Generate the ASDoc files

自动生成语言文档技术,目前官方的方法已被集成进FLEX环境中,可我还没找到,汗~~~~

Download and install the ASDoc tool from Adobe. I have created a little bat file I use with ASDoc just to make is easier to recreate the files whenever I need to without having to remember my settings, you can download it here. Run ASDoc to create your files. Click here to see the final ASDocs files.

Conclusion

If you develop Actionscript projects of any size and/or complexity, and you need some documentation done along the way, the steps I have outlined above are any excellent way to quickly generate both the stub code you need to begin your development and some project documentation, which as we all know is a hassle to create but invaluable to have. Enjoy

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

拜此文所赐,我也可以舒服的在EA中用UML来设计软件结构(改天和大家分享),进而直接生成代码了,不过,藉于EA的代码编辑器实在过于简单,个人的见议还是代码在FLEX中写,而框架、软件的设计在EA中进行。

Enterprise Architect可以在这里下载到:

http://www.topven.com/bbs/ShowPost.asp?ThreadID=181

分享到:
评论

相关推荐

    StartUml使用教程

    ### StartUml使用教程 #### 一、综述与背景介绍 StarUML(以下简称SU)是一款用于生成统一建模语言(Unified Modeling Language, UML)图表的强大工具,特别是类图和其他类型的图表。UML是一种广泛应用于软件工程...

    cpp-stub 中文使用手册

    单元测试打桩开源库 cpp-stub 使用手册 中文版本,这是从git上直接下载的,git上下载的源代码在arm上调用Stub.reset方法会引发段错误,在资源cpp-stub开源代码(下载地址:...

    StarUML.rar_pizza_starUML使用教程_staruml_uml

    StarUML(简称SU),是一种创建UML类图,并能够自动生成Java的“stub code” 的工具。SU也可以做JAVA逆向工程,以产生相应的UML图表。 在本教程中,我们将使用SU设计一个pizza饼。执行下列步骤,可以创建如下面所示的...

    startuml使用指导手册

    - 安装完成后,启动程序,首次使用时会遇到"New Project By Approach"对话框,可以选择"Empty Project",不勾选"设置为默认的做法"。 3. **创建新工程** - 在"Model Explorer"中,选择"Untitled"模块,可以通过...

    使用axis1生成stub客户端样例

    在IT行业中,Web服务是一种允许不同应用程序之间进行通信和数据交换的技术。Axis1是一个流行的开源SOAP(简单对象访问协议)工具包,它被广泛用于创建和使用Web服务。本示例将详细介绍如何使用Axis1生成Stub客户端,...

    cpp-stub 开源代码

    在这个特定的案例中,`cpp-stub` 存在一个在ARM平台上运行时的BUG,当尝试使用 `stub.h` 中的 `reset` 方法时,会触发段错误(Segmentation Fault),这是一个严重的问题,因为它会导致程序崩溃。 首先,我们来理解...

    startUml Uml基础知识指导

    9. **代码生成(Code Generation)**:StarUML可以自动生成Java的“stub code”,即类的骨架代码,但不会生成具体的功能实现。用户需要根据生成的代码框架添加实际业务逻辑。 10. **操作流程**:按照上述步骤,用户...

    Star UML指导手册

    StarUML是一款强大的建模工具,主要用于生成UML模型,包括类图,并能自动生成Java的Stub Code,方便进行进一步的编程实现。此外,它还支持逆向工程,能将已有的Java代码转换为对应的UML图表。 安装StarUML的过程...

    [PE变形]拓展STUB

    标题中的“[PE变形]拓展STUB”是指在PE(Portable Executable)文件格式中,对可执行文件的STUB部分进行变换的技术。PE文件格式是Windows操作系统中用于存放应用程序和动态链接库的主要格式。STUB,即Stub Section,...

    Microsoft Codeview and Utilities User's Guide

    11.10.3 Redirecting CodeView Input and Output 11.10.4 Commands Used with Redirection Chapter 12 Debugging in Protected Mode 12.1 Using CodeView in Different Modes 12.2 Debugging Dynamic-Link ...

    gtest stub 详细用法,附件用例,链接

    gtest stub 详细用法,附件用例,链接

    gdb-stub.rar_gdb stub

    "gdb-stub"是一个专为嵌入式系统设计的轻量级调试设施,允许开发者通过GDB远程控制目标设备上的程序执行。 标题“gdb-stub.rar_gdb stub”暗示了这个压缩包包含了一个与GDB相关的调试桩(stub)代码,可能是一个...

    OPC COM ProxyStub MergeModule (x86) 105.1

    OPC(OLE for Process Control)是微软为工业自动化领域提供的一种接口标准,它允许不同的软件系统之间进行数据交换。在标题“OPC COM ProxyStub MergeModule (x86) 105.1”中,我们可以看到几个关键点:OPC、COM、...

    uml入门指南

    整个StarUML入门指南不仅仅是一个简单的使用手册,更是一个关于如何利用UML和StarUML工具进行软件设计和开发的实践教程。它清晰地介绍了软件开发过程中从模型构建到代码生成的各个阶段,帮助开发者更有效地进行面向...

    starUML汉化增强版

    在描述中提到,StarUML具有生成Java“stub code”的功能,这意味着它不仅可以帮助设计系统架构,还可以自动生成基础代码框架。这极大地提高了开发效率,减少了手动编写基础代码的工作量。开发者只需要根据UML模型,...

    corba技术简介 IDL Stub

    主要讲述了Corba组件的关键技术。对IDL编译器以及客户Stub和服务器skeleton有更深入的了解。

    DDR3_fly-by拓扑设计

    3. 使用仿真工具进行设计评估:在设计中,我们可以使用仿真工具来评估长分支对信号的影响,以确保设计的可靠性。 DDR3 fly-by 拓扑设计的设计参考: 1. 负载走线阻抗要比主线阻抗高,建议主线阻抗控制到 40-45ohm...

    Android应用:StubView显示与隐藏

    在Android应用开发中,`StubView`是一种非常实用的组件,它允许我们在程序运行时动态地加载布局。在本文中,我们将深入探讨如何在Android应用中实现`StubView`的显示与隐藏,以及相关的源代码实践。 首先,`Stub...

    使用RMI和CORBA进行分布式java程序设计

    分布式程序设计是一种技术,允许不同计算机上的程序协同工作,仿佛它们都在同一台机器上运行。在Java世界中,RMI(Remote Method Invocation,远程方法调用)和CORBA(Common Object Request Broker Architecture,...

    OPC COM ProxyStub MergeModule (x86)_foundation_proxy_usvfs_proxy

    OPC(OLE for Process Control)是一种在自动化行业中广泛使用的接口技术,它允许不同的软件系统之间进行数据交换和通信。在本案例中,"OPC COM ProxyStub MergeModule (x86)_foundation_proxy_usvfs_proxy" 提供的...

Global site tag (gtag.js) - Google Analytics