Feb 19, 2007

Symbian Coding Conventions : Classes

'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'.

'C' Classes
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:
  1. They are allocated on the heap (dynamically allocated) — not on the stack, and not as members of other classes.
  2. The allocator used for this class hierarchy initializes all member data to binary zeroes.
  3. 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.
  4. They have a virtual destructor, which is used for standard cleanup processing.
  5. They support two-phased construction – this will be covered later in the section.


'R' Classes
These classes are used to access system resources, for example files, via handles. The following are characteristics of ‘R’ classes:
  1. They contain a handle that is used to pass on requests to other objects.
  2. 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.
  3. They may be freely bit-wise copied.
  4. They have no explicit constructor, destructor, copy constructor or assignment operator.

'M' Classes
Characteristic:
  1. Abstract
  2. Pure virtual functions
  3. No member data
Purpose:
  1. define an interface
Advantage:
  1. reduce dependencies between classes
Rule:
  1. the only use of multiple inheritance
  2. A C class derive from one other C class and zero or more M classes
'M'classes have the following restrictions:
  1. They should contain no member data.
  2. They should not contain constructors or destructors, or overloaded operators.
'M' classes usually contain pure virtual functions that define a fully abstract interface.

No comments: