The key is to use the right tool for each task. For a majority of programming tasks, object-oriented techniques is the preferred approach. Products such as Rogue Wave’s Tools.h++ Library, which encapsulate the Standard C++ Library with a familiar object-oriented interface, provide the power and advantages of object-orientation.

Use Standard C++ Library components directly when you need flexibility or highly efficient code. Use the more traditional approach to object-oriented design, such as encapsulation and inheritance, to model larger problem domains and knit all the pieces into a complete solution. To devise an architecture for your application, use encapsulation and inheritance to compartmentalize the problem. For an efficient data structure or algorithm for a compact problem that often resolves to a single class, use the Standard C++ Library. Use this library to create reusable classes when low-level constructs are needed. Use traditional OOP techniques to combine classes to solve a larger problem.

In future, most libraries will use the Standard C++ Library as their foundation. Using the Standard C++ Library, either directly or through an encapsulation such as Tools.h++ Library, ensures interoperability. This is important in large projects that may rely on communication among several libraries. A good thumb rule is to use the highest encapsulation level available to you, but make sure that the Standard C++ Library is available as the base for inter-library communication and operation.

The C++ language supports a wide range of programming approaches. The language, and the Standard C++ Library that supports it, are designed to give you the flexibility to approach each unique problem from the best possible angle.

The Standard C++ Library, when combined with traditional OOP techniques, is a flexible tool to build a collection of C++ classes. These classes can stand alone as a library or are tailored to a specific task.

Differences between Standard C++ Library and Other Libraries

A major portion of the Standard C++ Library is comprises a collection of class definitions for standard data structures, and a collection of algorithms commonly used to manipulate such structures. This part of the library is derived from the Standard Template Library (STL). The organization and design of this part of the library differs in almost all respects from the design of most other C++ class libraries, because it avoids encapsulation and uses almost no inheritance.

An emphasis on encapsulation is a key hallmark of object-oriented programming. The emphasis on combining data and functionality into an object is a powerful organization principle in software development; indeed it is the primary organizational technique.

Inheritance is a powerful technique to share code and reuse software. It is applicable when two or more classes share a common set of basic features. For example, in a graphical user interface, two types of windows may inherit from a common base window class, and the individual subclasses provide any required unique features. In another use of inheritance, object-oriented container classes may ensure common behavior and support code reuse by inheriting from a more general class, and factoring out common member functions.

The designers of the STL decided against using an entirely object-oriented approach, and separated the tasks to be performed using common data structures from the representation of the structures themselves. The STL is designed as a collection of algorithms and a separate collection of data structures that are manipulated using the algorithms.

The Non-Object-Oriented Design of the Standard C++ Library

The portion of the Standard C++ Library derived from the STL was purposely designed with an architecture that is not object-oriented. This design has both advantages and disadvantages. Some of them are mentioned below.

Creating and Using Libraries 177

Page 177
Image 177
HP C/aC++ for PA-RISC Software manual Differences between Standard C++ Library and Other Libraries