4.1 Introduction

Understanding how to implement a new class or modify an existing class is a basic skill in object-oriented programming. While it is always preferable to reuse intact an existing class that is suited to the needs of the system being built, it is often the case that a suitable class does not exist or the existing classes do not fully provide the attributes and behavior that are required. In these cases it is necessary to design and implement a new class or alter the design and implementation of an existing class.

Implementing a new class is a challenging activity because it involves the interaction of several very different types of knowledge and abilities, among which are:

  • aggregation: This is the conceptual foundation of a class. A good class cannot be designed without a good understanding of how to recognize aggregations, identify the parts of the aggregation, and define the relationships among these parts.

  • language features: This is the programming foundation of a class. To implement a class it is necessary to have a thorough understanding of the syntax and meaning of the parts of the language that bear on the structure and operation of an object. For example, understanding how to construct fully and destruct safely objects with complex internal structures is necessary.

  • style: Like many creative activities, programming involves an element of style, which in this context refers to the arrangement, naming, and presentation of the code for a class. Beyond purely aesthetic considerations, good programming style materially improves the readability of code.

  • tools: Almost any system involves not a single new class but many new classes that must not only be designed and implemented but also tested, debugged, recompiled, and managed. Performing these tasks efficiently involves proficiency in the use of tools. Basic tools for debugging and (re)building a system are studied in this chapter.

  • design: The design of a system - the assignment of responsibilities and the organization of collaborations - largely determines the performance and software engineering properties (e.g., maintainability) of the system. A good design results from the combination of insight, understanding, inspiration, experience, and hard work. Two basic aspects of design are how to recognize abstractions that should be represented as classes and how to represent the design of a system in a succinct, diagrammatic form.

Because all of these areas of knowledge and skills are interwoven, they cannot be separated perfectly for study individually. Any approach to learning these topics must focus on some of them and defer others, not because the deferred topics are less important but only because some place must be chosen as the starting point.

This chapter is primarily concerned with the issues of aggregation and language features. The use of tools and the ideas about design are covered in chapters 5 and 9, respectively.


Implementation Issues:

Implementing a New Class
Using Aggregation

Defining the Implementation

Organizing the Code


Kinds of Aggregations:

Simple Static Aggregation

More Complex
Static Aggregation

Dynamic Aggregation

Making Classes Safe:

Controlling Change

Copy Constructors

Assignment Operator

Other Class Features

©1998 Prentice-Hall, Inc.
A Simon & Schuster Company
Upper Saddle River, New Jersey 07458

Legal Statement