Difference between revisions of "Cpp Coding Standards/CLSDESIGN"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
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]].
+
== Class Design (CLSDESIGN)==
----
+
''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 [[../VIRTUAL|Virtual Classes]]. Encapsulation related items are in topic [[../ENC|Encapsulation]].''
=== Summary ===
+
==== One Responsibility <span id="OneResp">(OneResp)</span> ====
+
Give one class only one cohesive responsibility.
+
  
[[/OneResp|Details]]
+
===== One Responsibility <span id="OneResp">(OneResp)</span> =====
 +
Give one class only one cohesive responsibility. [[/OneResp|-> Details]]
  
==== How to Inherit <span id="Inherit">(Inherit)</span> ====
+
===== 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. [[/Inherit|-> Details]]
  
[[/Inherit|Details]]
+
===== No Implicit Conversions <span id="NoConv">(NoConv)</span> =====
 +
Make single argument constructors “explicit”. Be aware of default arguments.<br>
 +
Do not provide operator TYPE() functions.<br>
 +
[[/NoConv|-> Details]]
  
==== No Implicit Conversions <span id="NoConv">(NoConv)</span> ====
+
===== Specific new and delete <span id="NewDel">(NewDel)</span> =====
Make single argument constructors “explicit”. Be aware of default arguments.
+
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.)<br>
 
+
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).<br>
Do not provide operator TYPE() functions.
+
[[/NewDel|-> Details]]
 
+
----
[[/NoConv|Details]]
+
==== Related Rules ====
 
+
'''Describe the Class Responsibility''' [[../CODEDOC#ClassResp|-> CODEDOC:ClassResp]]
==== Specific new and delete <span id="NewDel">(NewDel)</span> ====
+
* All items of topic [[../ENC|Encapsulation]]
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.)
+
* All items of topic [[../IFC|Interfaces]]
 
+
* All items of topic [[../CLSINIT|Class Construction, Destruction and Copying]]
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).
+
* All items of topic [[../VIRTUAL|Virtual Classes]]
 
+
[[/NewDel|Details]]
+
----  
+
=== Related Rules ===
+
* [[../Class Construction, Destruction and Copying |CLSINIT]] - all items
+
* [[../Code Documentation#ClassResp | CODEDOC:ClassResp]] - ClassResponsibility
+
* [[../Encapsulation |ENC]] – all items
+
* [[../Virtual Classes |VIRTUAL]] – all items
+
* [[../Interfaces |IFC]] – all items
+
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Latest revision as of 09:02, 23 May 2007

Class Design (CLSDESIGN)

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.

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

Describe the Class Responsibility -> CODEDOC:ClassResp


Personal tools