Difference between revisions of "Cpp Coding Standards/CLSDESIGN"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m
 
(10 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 [[../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]].
+
== 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_2 |One Responsibility]] ====
+
Give one class only one cohesive responsibility.
+
 
+
==== Inherit ====
+
Inherit to be reused, not to reuse. Else prefer composition over inheritance.
+
  
==== No Implicit Conversions ====
+
===== One Responsibility <span id="OneResp">(OneResp)</span> =====
Make single argument constructors “explicit”. Be aware of default arguments.
+
Give one class only one cohesive responsibility. [[/OneResp|-> Details]]
Do not provide operator TYPE() functions.
+
  
==== Specific New and Delete ====
+
===== How to Inherit <span id="Inherit">(Inherit)</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.)
+
Inherit to be reused, not to reuse. Else prefer composition over inheritance. [[/Inherit|-> Details]]
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).
+
  
----
+
===== No Implicit Conversions <span id="NoConv">(NoConv)</span> =====
=== Related Rules ===
+
Make single argument constructors “explicit”. Be aware of default arguments.<br>
* [[../CLSINIT | CLSINIT]] – all items
+
Do not provide operator TYPE() functions.<br>
* [[../CODEDOCU#ClassResponsibility  | CODEDOCU:ClassResponsibility]]
+
[[/NoConv|-> Details]]
* [[../ENC | ENC]] – all items
+
* [[../HIERARCHY | HIERARCHY]] – all items
+
* [[../IFC | IFC]] – all items
+
  
 +
===== 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.)<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>
 +
[[/NewDel|-> Details]]
 
----
 
----
=== Explanations ===
+
==== Related Rules ====
==== One Responsibility ====
+
'''Describe the Class Responsibility''' [[../CODEDOC#ClassResp|-> CODEDOC:ClassResp]]
It is preferable to focus on one thing at a time. This avoids implementation problems with diverging requirements and allows easier learning for users and maintainers of the class.
+
* All items of topic [[../ENC|Encapsulation]]
===== Example =====
+
* All items of topic [[../IFC|Interfaces]]
std::basic_string is a well known example of a class that wants to do too many things at once.  
+
* All items of topic [[../CLSINIT|Class Construction, Destruction and Copying]]
 +
* All items of topic [[../VIRTUAL|Virtual Classes]]
  
 
----
 
----
 
[[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