Previous | Next | Table of Contents | Index | Program List | Copyright

15.1 System Structures: Object-Oriented Programming

Object-oriented programming (OOP) is a programming methodology that relies on a number of language features. These are:

In OOP, an object has two important characteristics:

  1. It has state, that is, it has a value that may change over time.
  2. It has behavior, that is, it has a set of operations that act on it, and these operations are the only ones that can change its state (value).

In working with this book, you have been using OOP concepts since the earliest chapters, although we did not call it that. You have been working with Ada variables; object is just a more modern name for variable. As you know, each variable has a type, and can take on only values from that type's set of values.

Also, each type has a set of operations associated with it. The predefined types, such as Integer or Ada.Calendar.Time, all have predefined operations, and only the given operations are valid for values of the given type. Throughout the book, we have emphasized Ada compilers' concern for validity of operations, giving compilation errors where possible, or compiling run-time checks into your program where necessary.

Further, you have used packages right along, starting with the input/output packages and other predefined packages such as Ada.Calendar and Ada.Numerics. You have used other packages and perhaps even written one or two yourself. Having reached this point, you are quite accustomed to encapsulation.

In Chapter 10 you explored the idea of doing your own encapsulation, writing new types and sets of operations, and implementing these in ADT packages. Most of the ADTs in Chapter 10 defined PRIVATE record types; PRIVATE types allowed us to control precisely which predefined and programmer-defined operations were valid. This precision of control over operations is a very important aspect of OOP.

Chapter 11 introduced you to writing generic packages; in earlier chapters you used generics like Ada.Text_IO.Enumeration_IO and Ada.Strings.Bounded. You are, therefore, at least a bit familiar with genericity.

Some writers use the term object-based programming to describe programming that uses "only" encapsulation and genericity but not inheritance and polymorphism. These writers believe inheritance and polymorphism to be of paramount importance and that any program that doesn't take advantage of these two concepts is simply not object-oriented. We think the distinction is somewhat artificial; encapsulation and genericity are just as important in developing good object-oriented designs.


Previous | Next | Table of Contents | Index | Program List | Copyright

Copyright © 1996 by Addison-Wesley Publishing Company, Inc.