Difference between revisions of "Cpp Coding Standards/CLSDESIGN"
(format) |
m |
||
Line 1: | Line 1: | ||
=== Class Design (CLSDESIGN) - Summary === | === Class Design (CLSDESIGN) - Summary === | ||
''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]].'' | ''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]].'' | ||
− | + | ||
==== One Responsibility <span id="OneResp">(OneResp)</span> ==== | ==== One Responsibility <span id="OneResp">(OneResp)</span> ==== | ||
Give one class only one cohesive responsibility. [[/OneResp|-> Details]] | Give one class only one cohesive responsibility. [[/OneResp|-> Details]] |
Revision as of 13:46, 22 May 2007
Contents
Class Design (CLSDESIGN) - Summary
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
- CLSINIT - all items
- CODEDOC:ClassResp - ClassResponsibility
- ENC – all items
- VIRTUAL – all items
- IFC – all items