Object-oriented design guidelines
C++ programming conventions
Taligent environment programming conventions
Taligent environment programming tips and techniques
Portability issues
Class templates
Architectural goals
Object-oriented architecture
All interfaces are expressed through objects
Commonality is managed through inheritance
Objects are leveraged wherever possible
Frameworks provide the foundation
Let resources find you
Putting it all together
Object-oriented design guidelines
Reflect the client's view
Let resources find you
Express all interfaces through objects
Preserve class invariants
Object-oriented design with C++
C++ doesn't express full object interface
C++ requires definition of special member functions
Abstract base classes
Use type inheritance to share protocol
Useimplementation inheritance to override behavior
Design the interfaces between the base and derived classes
Expected calls
Group override
Getters and setters
Guarantee use of derived classes as arguments
Implement full protocol in derived classes
Preserve semantics in a derived class
Avoid deep nesting in lightweight objects
Multiple inheritance
Be aware of problems with virtual bases
Avoid multiple occurrences of a base
Performance by design
Design performance in
Conduct performance analysis
Perform controlled experiments
Use static objects instead of temporaries
Use chunky iteration for performance
Use cache objects
Common design problems and pitfalls
Object bloat
Lost object focus
Hardening of the architecture
Managers are not objects
Collections of functions are not objects
Encapsulation leakage
Empty base classes
Overeducated base classes
Overachieving base classes
Distinguish is-a from has-a relationships
C++ programming conventions
The C++ standard
Source file conventions
Include copyright notices
Use comments
Include function prototypes
Do not use code names in filenames
Enclose definitions in header files
Include only related classes in one file
Name conventions
Use specific names
But use generic names for abstract base classes
Avoid abbreviations
Use special names for copy, create, and adopt routines
Use global names only for classes
Avoid ordinary globals
Class definition conventions
Follow member function conventions
State explicit use of public, private, and protected
Use separate class definition sections
Type declaration conventions
Avoid raw C types with dimensions
Use dimensionless raw C types
Avoid type casting
Silent coercion
Cast operators
Use consistent return types for assignment operators
State typedef class names before specifications
Arguments and function results
Pass variables when possible
Use array arguments instead of pointers
Limit default arguments
Avoid functions with unspecified arguments (...)
Avoid returning pointers without allocation
Reference and value semantics: C++ versus everything else
Use pointers to make multiple references
Use references for a one-time reference
Allocate storage only if you must
Pretend everything is a primitive
Static object constructors
The C preprocessor
Use const instead of #define constants
Use enum instead of sets of constants
Use inlines instead of function macros
Use templates for specialized functions and classes
Things to avoid
Don't use goto
Avoid magic numbers
Avoid bit flags (& and |)
Avoid using arrays as local variables or object fields
Taligent environment programming conventions
Taligent libraries
Avoid homegrown utility classes
Use the Name Server
Storage management philosophy
Hide allocation inside a class
Don't assume use of a heap
Clarify ownership of storage in interfaces
Don't use very large local variables or members
Shared libraries
Avoid static objects
Modifiable statics in a library
Consider alternatives to temporary objects
Binary compatibility considerations
Adding virtual and nonvirtual functions
Changing a function from inline to noninline
Removing private nonvirtual functions not called by inlines
Using classes internal to your implementation
Use virtual functions if overrides are possible
Rearranging, adding, and removing private data members with restrictions
Inline functions
Inlines that call something else
Inline function definitions in .C files
Inlines for extreme efficiency
Don't write inlines in declarations
Inlines for exporting private and protected members
Empty special members
Virtual inline functions where the type is not known
Virtual functions
Define class abstractions
Decide now what might be overridden later
When to use pure virtual functions
Private virtual functions to control access
Base class constructors cannot call virtual functions
The cost of failing to call Initialize()
Destructors are not automatically virtual
Switch statements indicate polymorphism
When to use virtual assignment
Friend functions and classes
Exception handling
Exceptions checklist
Exceptions syntax
Avoid interface specification
Perform resource recovery
Automatic objects
Passing exceptions
Design exception classes
What to subclass
When to subclass
When to signal an exception
When to recover an exception
Portable hash
Strive for uniform distribution
Do not implement Hash via member functions
When equality does not apply
Equality sample
Equality between different types
Taligent environment programming tips and techniques
Surrogate objects
Taxonomy of surrogates
Explicit masters
Handle surrogates
Hidden masters
Surrogates that view masters
Storage management issues
Follow naming conventions
Use copy semantics wherever possible
Avoid storage manipulation in open code
Allocate subobjects on the heap for debugging
Concurrency and shared library issues
Synchronization techniques
Synchronization and problems with memory access
Synchronization of global and static variables
Shared memory between tasks
Shared heaps
Shared memory problems with const
Static destructors for subsystem cleanup
Miscellaneous programming tips
Create objects in a valid state
Use flattening rather than dynamic class instantiation
Check for self-assignment with operator=:
Balance overloaded operators
Use static members as constructors
Differentiate overloaded constructors
Hide implementation classes
Use nil pointer deletion
Issues in overloading and overriding classes
Control class access
Portability issues
Language and hardware assumptions
Safe assumptions
Bad assumptions
Portable data
Assembly language
Nonportable code
Class templates
Definitions and conventions
Template conventions
Include file conventions
Sharing class template implementations
General rules for implementation classes
The example class: an owning stack
Sharing the implementation through private inheritance
Class definitions
Naming conventions
Instance variables
Type-specific methods and implementation class constructors and destructors
Inlining the class template's public methods
Class templates that inherit from specialized classes
An implementation sharing example
Sharing the implementation by delegating to a member
An example of delegating to a member
The delegation example's naming conventions
The delegating-to-a-member example
Further reading

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker