最近比賽告一段落了,要開始學習Symbian的學習,發現....還蠻多東西要看的,像是基本的Coding conventions更為重要啊。以下是在Symbain上Coding時需要注意的convention:
(此資料轉載於Blue119's blog)
Function Convention
- Trailing "D" indicates the deletion of an object
- Trailing "L" means function may leave
- Trailing "C" means an item is placed on the cleanup stack
-------------------------------------------
Variable Convention
- Member variables' names begin with 'i'
- Arguments' names begin with 'a'
- Automatics' (local variables) names have no initial letter, but start in lower case
- Constants' names begin with 'K'
- Global variables are usually avoided, but when used, their names begin with a capital letter.
-----------------------------------
Class Convention
'T' Classes
- Classes that don't own external objects/resources and so can be declared on the stack 'T'types contain their value.
- They do not own any external object, either directly (by pointer) or indirectly (by handle).
- they do not need a destructor to cleanup resources.
- 'T' types may be allocated either on the stack (that is locally as C++ automatic variables) or as members of other classes.
- note that the default stack size is 8KB in Symbian OS.
- Structure types mostly begin with 'T'.
If a class needs to dynamically allocate any memory or own another class, it should derive, directly or indirectly, from CBase (a built-in Symbian OS class), and its class name should begin with 'C'. CBase-derived classes have the following properties:
- They are allocated on the heap (dynamically allocated) — not on the stack, and not as members of other classes.
- The allocator used for this class hierarchy initializes all member data to binary zeroes.
- They are passed by pointer, or reference, and so do not need an explicit copy constructor or assignment operator unless there is clear intention that a particular class supports copying.
- They have a virtual destructor, which is used for standard cleanup processing.
- They support two-phased construction – this will be covered later in the section.
These classes are used to access system resources, for example files, via handles. The following are characteristics of ‘R’ classes:
- They contain a handle that is used to pass on requests to other objects.
- They are opened using an "Open()" function particular to the ‘R’ class, and closed using a "Close()" function particular to the class. An ‘R’ object must be closed once if it has been opened.
- They may be freely bit-wise copied.
- They have no explicit constructor, destructor, copy constructor or assignment operator.
Characteristic:
- Abstract
- Pure virtual functions
- No member data
- define an interface
- reduce dependencies between classes
- the only use of multiple inheritance
- A C class derive from one other C class and zero or more M classes
- They should contain no member data.
- They should not contain constructors or destructors, or overloaded operators.
轉載自Blue119's blog:Symbian Coding Conventions:Class
沒有留言:
張貼留言