TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Category: Object Oriented Programming

Synopsis:Class Organization


Description:
This chapter concerns parts of object-oriented programming, such as encapsulation, inheritance, polymorphism and associations.

Coding Rules

NameCheckedSynopsis
OOP#001 Checked automatically with code checker A class that manages resources shall declare a copy constructor, a copy assignment operator, and a destructor
OOP#002 A public method must never return a non-const reference or pointer to member data
OOP#003 A public method must never return a non-const reference or pointer to data outside an object, unless the object shares the data with other objects
OOP#004 Checked automatically with code checker If you derive from more than one base class with the same parent, that parent shall be a virtual base class that has a default constructor and no data members
OOP#005 Do use references for associations with cardinality '1' whenever possible
OOP#006 Checked automatically with code checker A function should not return a raw pointer
OOP#007 Selection statements (if-else and switch) should be used when the control flow depends on an object's value; dynamic binding should be used when the control flow depends on the object's type
OOP#008 Checked automatically with code checker Encapsulate global variables and constants, enumerated types, and typedefs in a class or in a namespace
OOP#009 Avoid inheritance for parts-of relations
OOP#010 Checked automatically with code checker Avoid multiple inheritance
OOP#011 Checked automatically with code checker Never redefine an inherited non-virtual method
OOP#012 Use C++ to describe preconditions, postconditions, exceptions, and class invariants
OOP#013 Checked automatically with code checker A public base class must have either a public virtual destructor or a protected destructor
OOP#014 Document the interface of template parameters
OOP#015 Checked automatically with code checker Friends of a class should be avoided
OOP#016 Specify functions using preconditions, postconditions, exceptions; specify classes using invariants
OOP#017 It shall be possible to use a pointer or reference to an object of a derived class wherever a pointer or reference to a public base class object is used
OOP#018 Checked automatically with code checker When overriding a (virtual) function from a base class, the derived class should give the same const modifier to the function.