[Contents] [Previous] [Next]

Classes

An object is defined by a class, which is a description of the data and actions shared by all objects that belong to that class. Each object created from a class is called an instance of that class. Programmers use classes like cookie cutters to create, or instantiate, objects with particular data members and member functions.

Figure 8 shows how this might work with the TWindow object described in the preceding section. To create an object from a class like TWindow from within a program, a programmer instantiates it--that is, uses the definitions provided by the class to create a single working window object that has all those characteristics.

Instantiation saves the work of recreating the data members and member functions each time the program needs to create a window. Instead, one line of code instantiates or "stamps out" the object in a form that's ready to use. Each actual window on the screen corresponds to a separate instance of an object instantiated from class TWindow.

Every instantiation creates a new set of data members but shares a single copy of the code that implements the member functions. Every TWindow object has the same data members as all other TWindow objects, but the values of its data members are different, corresponding to its unique size and position on the screen.



[Contents] [Previous] [Next]

Addison-Wesley Publishing Company, Copyright©1995 by Sean Cotter and Taligent,Inc. All rights reserved.