next up previous
Next: Advanced examples Up: C++ Design Issues Previous: Specify Interfaces

Class in C++

The key notion of C++ is class. A C++ class is a type. Together with namespaces, classes are also a primary mechanism for information hiding. Programs can be specified in terms of user-defined types and hierarchies of such user-defined types. Both built-in and user-defined types obey statically checked type rules. Virtual functions provide a mechanism for run-time binding without breaking the static type rules. Templates support the design of parameterized types. Exceptions provide a way of making error handling more regular. These C++ features can be used without incurring overhead compared to C programs. These are the first-order properties of C++ that must be understood and considered by a designer.

In addition, generally available major libraries ( such as matrix libraries, database interfaces, graphical user interface libraries, and concurrency support libraries ) can strongly affect design choices.

Fear of novelty sometimes leads to sub-optimal use of C++. So does misapplication of lessons from other languages, systems, and application areas. Poor design tools can also warp designs.

Five ways designers fail to take advantage of language features and fail to respect limitations are worth mentioning:

These variants are typical for designers with

Try to avoid the traps above. Use procedural part of C++, classes, inheritance, generic programming (eg. template functions and template classes), polymorphism (eg. use of virtual functions) and static typechecking in a ballance.


next up previous
Next: Advanced examples Up: C++ Design Issues Previous: Specify Interfaces
Porkoláb Zoltán 2001-09-03