[转]让你的Flex MXML和ActionScript 3代码更规范:第三篇:文件组织篇
File Organization(文件组织)
这部分旨在说明一个Flex框架文件应该怎么组织
--------------------------------------------------------------------------------------------------------
版本说明(Copyright notice)
框架中的每一个as文件都包括一个版本说明,2008开源版本说明格式如下:
////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
注意是80个字符宽度
--------------------------------------------------------------------------------------------------------
包说明(package statement)
TBD
--------------------------------------------------------------------------------------------------------
导入部分说明(import statements)
TBD
--------------------------------------------------------------------------------------------------------
命名空间说明(use namespace statement)
TBD
--------------------------------------------------------------------------------------------------------
类标签(Class metadata)
这部分组织类标签,包括Event、Styles、Effects、Excluded APIs和其他的标签
对应每个标签在前面均有一小部分说明,注意这部分是40字符宽度,而且在//和标签名前留有2个空格距离
每个部分标签按标签name的名字首字母依次排序,对于其他没有name属性的,按标签类型名字排序
例子如下:
//--------------------------------------
// Events
//--------------------------------------
/
**
* ASDoc comment.
*/
[Event
/**
* ASDoc comment.
*/
[Event
//--------------------------------------
// Styles
//--------------------------------------
/**
* ASDoc comment.
*/
[Style
/**
* ASDoc comment.
*/
[Style]
//--------------------------------------
// Effects
//--------------------------------------
/**
* ASDoc comment.
*/
[Effect
/**
* ASDoc comment.
*/
[Effect]
//--------------------------------------
// Excluded APIs
//--------------------------------------
[Exclude(name="horizontalAlign", kind="style")]
[Exclude(name="verticalAlign", kind="style")]
//--------------------------------------
// Other metadata
//--------------------------------------
[DefaultBindingProperty(source="text", destination="text")]
[IconFile("Text.png")]--------------------------------------------------------------------------------------------------------
类声明(Class declaration)
TBD
--------------------------------------------------------------------------------------------------------
包括Version.as文件(include statement for Version.as)
每个类都应该包含core/Version.as文件来作为相互间联系路径,Version.as文件中有对Version的静态常量声明
include "../core/Version.as";--------------------------------------------------------------------------------------------------------
Implementation notes
TBD
--------------------------------------------------------------------------------------------------------
Class initialization
TBD
--------------------------------------------------------------------------------------------------------
类常量(Class constants)
这使用static const声明
ActionScript 3不允许Array和Object类型声明为常量,应该把他们声明为static var而不是static const,把他们放在这部分是因为在概念上他们属于这个范畴
--------------------------------------------------------------------------------------------------------
Class mix-ins
Declare any static variables of type Function that get mixed in rather than being declared as methods.
--------------------------------------------------------------------------------------------------------
Class resources
TBD
--------------------------------------------------------------------------------------------------------
Class variables
TBD
--------------------------------------------------------------------------------------------------------
类属性(Class properties)
定义static的getters和setters,对他们按名字母排序,同时对每个getter和setter在签名加以简短说明
Declare static getters and setters here. Order them alphabetically by property name. Use a minor separator with the property name for each one. Put the getter before the setter.
--------------------------------------------------------------------------------------------------------
类方法(Class methods)
static function声明将放在这
--------------------------------------------------------------------------------------------------------
Constructor
TBD
--------------------------------------------------------------------------------------------------------
Variables
TBD
--------------------------------------------------------------------------------------------------------
重写属性(Overridden properties)
把重写的同时不是static的getter和setter放在这部分,同理按其名字字母排序,并在每个前相应加入简短说明
--------------------------------------------------------------------------------------------------------
属性(Properties)
把新的不属于static的属性放这部分,同理按其名字字母排序,并在每个前相应加入简短说明
--------------------------------------------------------------------------------------------------------
重写方法(Overridden methods)
把重写的不属于static的函数放这
--------------------------------------------------------------------------------------------------------
方法(Methods)
把新的不属于static的函数放这
--------------------------------------------------------------------------------------------------------
重写的事件处理(Overridden event handlers)
把重写的事件处理放这
--------------------------------------------------------------------------------------------------------
事件处理(Event handlers)
把新的事件处理放这
--------------------------------------------------------------------------------------------------------
包外的帮助类(Out-of-package helper classes)
TBD
--------------------------------------------------------------------------------------------------------
这部分好多TBD,大家要了解就多看SDK吧
这部分旨在说明一个Flex框架文件应该怎么组织
--------------------------------------------------------------------------------------------------------
版本说明(Copyright notice)
框架中的每一个as文件都包括一个版本说明,2008开源版本说明格式如下:
////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
注意是80个字符宽度
--------------------------------------------------------------------------------------------------------
包说明(package statement)
TBD
--------------------------------------------------------------------------------------------------------
导入部分说明(import statements)
TBD
--------------------------------------------------------------------------------------------------------
命名空间说明(use namespace statement)
TBD
--------------------------------------------------------------------------------------------------------
类标签(Class metadata)
这部分组织类标签,包括Event、Styles、Effects、Excluded APIs和其他的标签
对应每个标签在前面均有一小部分说明,注意这部分是40字符宽度,而且在//和标签名前留有2个空格距离
每个部分标签按标签name的名字首字母依次排序,对于其他没有name属性的,按标签类型名字排序
例子如下:
//--------------------------------------
// Events
//--------------------------------------
/
**
* ASDoc comment.
*/
[Event
/**
* ASDoc comment.
*/
[Event
//--------------------------------------
// Styles
//--------------------------------------
/**
* ASDoc comment.
*/
[Style
/**
* ASDoc comment.
*/
[Style]
//--------------------------------------
// Effects
//--------------------------------------
/**
* ASDoc comment.
*/
[Effect
/**
* ASDoc comment.
*/
[Effect]
//--------------------------------------
// Excluded APIs
//--------------------------------------
[Exclude(name="horizontalAlign", kind="style")]
[Exclude(name="verticalAlign", kind="style")]
//--------------------------------------
// Other metadata
//--------------------------------------
[DefaultBindingProperty(source="text", destination="text")]
[IconFile("Text.png")]--------------------------------------------------------------------------------------------------------
类声明(Class declaration)
TBD
--------------------------------------------------------------------------------------------------------
包括Version.as文件(include statement for Version.as)
每个类都应该包含core/Version.as文件来作为相互间联系路径,Version.as文件中有对Version的静态常量声明
include "../core/Version.as";--------------------------------------------------------------------------------------------------------
Implementation notes
TBD
--------------------------------------------------------------------------------------------------------
Class initialization
TBD
--------------------------------------------------------------------------------------------------------
类常量(Class constants)
这使用static const声明
ActionScript 3不允许Array和Object类型声明为常量,应该把他们声明为static var而不是static const,把他们放在这部分是因为在概念上他们属于这个范畴
--------------------------------------------------------------------------------------------------------
Class mix-ins
Declare any static variables of type Function that get mixed in rather than being declared as methods.
--------------------------------------------------------------------------------------------------------
Class resources
TBD
--------------------------------------------------------------------------------------------------------
Class variables
TBD
--------------------------------------------------------------------------------------------------------
类属性(Class properties)
定义static的getters和setters,对他们按名字母排序,同时对每个getter和setter在签名加以简短说明
Declare static getters and setters here. Order them alphabetically by property name. Use a minor separator with the property name for each one. Put the getter before the setter.
--------------------------------------------------------------------------------------------------------
类方法(Class methods)
static function声明将放在这
--------------------------------------------------------------------------------------------------------
Constructor
TBD
--------------------------------------------------------------------------------------------------------
Variables
TBD
--------------------------------------------------------------------------------------------------------
重写属性(Overridden properties)
把重写的同时不是static的getter和setter放在这部分,同理按其名字字母排序,并在每个前相应加入简短说明
--------------------------------------------------------------------------------------------------------
属性(Properties)
把新的不属于static的属性放这部分,同理按其名字字母排序,并在每个前相应加入简短说明
--------------------------------------------------------------------------------------------------------
重写方法(Overridden methods)
把重写的不属于static的函数放这
--------------------------------------------------------------------------------------------------------
方法(Methods)
把新的不属于static的函数放这
--------------------------------------------------------------------------------------------------------
重写的事件处理(Overridden event handlers)
把重写的事件处理放这
--------------------------------------------------------------------------------------------------------
事件处理(Event handlers)
把新的事件处理放这
--------------------------------------------------------------------------------------------------------
包外的帮助类(Out-of-package helper classes)
TBD
--------------------------------------------------------------------------------------------------------
这部分好多TBD,大家要了解就多看SDK吧