2.2 Programming Paradigms
Object-oriented programming is a technique for programminga paradigm for writing "good" programs for a set of problems. If the term object-oriented programming language means anything, it must mean a programming language that provides mechanisms that support the object-oriented style of programming well.
There is an important distinction here. A language is said to support a style of programming if it provides facilities that make it convenient (reasonably easy, safe, and efficient) to use that style. A language does not support a technique if it takes exceptional effort or skill to write such programs; it merely enables the technique to be used. For example, you can write structured programs in Fortran77 and object-oriented programs in C, but it is unnecessarily hard to do so because these languages do not directly support those techniques.
Support for a paradigm comes not only in the obvious form of language facilities that allow direct use of the paradigm, but also in the more subtle form of compile-time and/or run-time checks against unintentional deviation from the paradigm. Type checking is the most obvious example of this; ambiguity detection and run-time checks are also used to extend linguistic support for paradigms. Extra-linguistic facilities such as libraries and programming environments can provide further support for paradigms.
One language is not necessarily better than another because it possesses a feature the other does not. There are many examples to the contrary. The important issue is not so much what features a language possesses, but that the features it does possess are sufficient to support the desired programming styles in the desired application areas:
All features must be cleanly and elegantly integrated into the language.
It must be possible to use features in combination to achieve solutions that would otherwise require extra, separate features.
There should be as few spurious and "special-purpose" features as possible.
A feature's implementation should not impose significant overheads on programs that do not require it.
A user should need to know only about the subset of the language explicitly used to write a program.
The first principle is an appeal to aesthetics and logic. The next two are expressions of the ideal of minimalism. The last two can be summarized as "what you don't know won't hurt you."
C++ was designed to support data abstraction, object-oriented programming, and generic programming in addition to traditional C programming techniques under these constraints. It was not meant to force one particular programming style upon all users.
The following sections consider some programming styles and the key language mechanisms supporting them. The presentation progresses through a series of techniques, starting with procedural programming and leading up to the use of class hierarchies in object-oriented programming and generic programming using templates. Each paradigm builds on its predecessors, each adds something new to the C++ programmer's toolbox, and each reflects a proven design approach.
The presentation of language features is not exhaustive. The emphasis is on design approaches and ways of organizing programs rather than on language details. At this stage, it is far more important to gain an idea of what can be done using C++ than to understand exactly how it can be achieved.