Difference between revisions of "Cpp Coding Standards/CLSDESIGN/Inherit"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m (Linked LSP)
Line 1: Line 1:
 
Avoid inheritance, because it induces the second highest coupling possible in c++ (second only to friendship). Instead, prefer composition by default.
 
Avoid inheritance, because it induces the second highest coupling possible in c++ (second only to friendship). Instead, prefer composition by default.
  
If you employ public inheritance, use it to be reused and not to reuse another implementation. That is, inherit publicly from a baseclass, to allow client code to use your class instead of the base class. Make sure you don't violate the LSP doing so.
+
If you employ public inheritance, use it to be reused and not to reuse another implementation. That is, inherit publicly from a baseclass, to allow client code to use your class instead of the base class. Make sure you don't violate the [[../../Virtual Classes/LSP |LSP]] doing so.

Revision as of 14:08, 16 February 2007

Avoid inheritance, because it induces the second highest coupling possible in c++ (second only to friendship). Instead, prefer composition by default.

If you employ public inheritance, use it to be reused and not to reuse another implementation. That is, inherit publicly from a baseclass, to allow client code to use your class instead of the base class. Make sure you don't violate the LSP doing so.

Personal tools