Difference between revisions of "Cpp Coding Standards/CLSDESIGN"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
General hints for class design. Items referring to constructors, destructors, copying and allocation (of classes) reside in topic [[../CLSINIT | Class Construction, Destruction and Copying]]. Items referring to virtual classes in hierarchies reside in [[../HIERARCHY | Hierarchies of Virtual Classes]]. Encapsulation related items are in topic [[../ENC | Encapsulation]].
+
General hints for class design. Items referring to constructors, destructors, copying and allocation (of classes) reside in topic [[../Class Construction, Destruction and Copying |Class Construction, Destruction and Copying]]. Items referring to virtual classes in hierarchies reside in [[../Virtual Classes |Virtual Classes]]. Encapsulation related items are in topic [[../Encapsulation |Encapsulation]].
 
----
 
----
 
=== Summary ===
 
=== Summary ===
==== [[#One Responsibility_2 |One Responsibility]] ====
+
==== One Responsibility <span id="OneResp">(OneResp)</span> ====
ID: [[../Details/CLSDESIGN:OneResp|'''OneResp''']]. Give one class only one cohesive responsibility.
+
Give one class only one cohesive responsibility.
  
==== How to Inherit ====
+
[[/OneResp|Details]]
 +
 
 +
==== How to Inherit <span id="Inherit">(Inherit)</span> ====
 
Inherit to be reused, not to reuse. Else prefer composition over inheritance.
 
Inherit to be reused, not to reuse. Else prefer composition over inheritance.
  
==== No Implicit Conversions ====
+
[[/Inherit|Details]]
 +
 
 +
==== No Implicit Conversions <span id="NoConv">(NoConv)</span> ====
 
Make single argument constructors “explicit”. Be aware of default arguments.
 
Make single argument constructors “explicit”. Be aware of default arguments.
 +
 
Do not provide operator TYPE() functions.
 
Do not provide operator TYPE() functions.
  
==== Specific new and delete ====
+
[[/NoConv|Details]]
 +
 
 +
==== Specific new and delete <span id="NewDel">(NewDel)</span> ====
 
When you provide a class-specific new or delete with custom parameters, provide the corresponding new or delete as well. (Not doing this causes memory leaks.)
 
When you provide a class-specific new or delete with custom parameters, provide the corresponding new or delete as well. (Not doing this causes memory leaks.)
 +
 
If you provide one class specific new, this hides all other variants of new. So you probably want to provide also the three all of the standard forms of new (plain, nothrow and inplace).
 
If you provide one class specific new, this hides all other variants of new. So you probably want to provide also the three all of the standard forms of new (plain, nothrow and inplace).
  
 +
[[/NewDel|Details]]
 
----  
 
----  
 
=== Related Rules ===
 
=== Related Rules ===
* [[../CLSINIT | CLSINIT]] all items
+
* [[../Class Construction, Destruction and Copying |CLSINIT]] - all items
* [[../CODEDOCU#ClassResponsibility  | CODEDOCU:ClassResponsibility]]
+
* [[../Code Documentation#ClassResp | CODEDOCU:ClassResp]] - ClassResponsibility
* [[../ENC | ENC]] – all items
+
* [[../Encapsulation |ENC]] – all items
* [[../HIERARCHY | HIERARCHY]] – all items
+
* [[../Virtual Classes |VIRTUAL]] – all items
* [[../IFC | IFC]] – all items
+
* [[../Interfaces |IFC]] – all items
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Revision as of 12:06, 29 November 2006

General hints for class design. Items referring to constructors, destructors, copying and allocation (of classes) reside in topic Class Construction, Destruction and Copying. Items referring to virtual classes in hierarchies reside in Virtual Classes. Encapsulation related items are in topic Encapsulation.


Summary

One Responsibility (OneResp)

Give one class only one cohesive responsibility.

Details

How to Inherit (Inherit)

Inherit to be reused, not to reuse. Else prefer composition over inheritance.

Details

No Implicit Conversions (NoConv)

Make single argument constructors “explicit”. Be aware of default arguments.

Do not provide operator TYPE() functions.

Details

Specific new and delete (NewDel)

When you provide a class-specific new or delete with custom parameters, provide the corresponding new or delete as well. (Not doing this causes memory leaks.)

If you provide one class specific new, this hides all other variants of new. So you probably want to provide also the three all of the standard forms of new (plain, nothrow and inplace).

Details


Related Rules


Personal tools