Compaq Reliable Transaction Router manual Messages Class Relationships

Models: Reliable Transaction Router

1 78
Download 78 pages 48.87 Kb
Page 42
Image 42

Object-Oriented Programming

Messages

Class Relationships

Example 2–1 Objects-Defined Sample

Dog.h: class Dog

{...

};

main.cpp: #include "Dog.h" main()

Dog King; Dog Fifi;

}

Objects communicate by sending messages. This is done by calling an object's methods.

Some principal categories of messages are:

Constructors: Create objects

Destructors: Delete objects

Selectors: Return part or all of an object's state. For example, a Get method

Modifiers: Change part or all of an object's state. For example, a Set method

Iterators: Access multiple element objects within a container object. For example, an array.

Classes can be related in the following ways:

Simple association: One class is aware of another class. For example, "Dog object is associated with a Master object." This is a "Knows a" relationship.

Composition: One class contains another class as part of its attributes. For example, "Dog objects contains Leg objects." This is a "Has a" relationship.

Inheritance A child class is derived from one or more parent, or base, classes. For example, "Mutt object derives from Collie object and Boxer object which both derive from Dog object." This is an "Is a" relationship. Inheritance enables the use of polymorphism.

2–8Architectural Concepts

Page 42
Image 42
Compaq Reliable Transaction Router manual Messages Class Relationships, Example 2-1 Objects-Defined Sample