beautypg.com

Retrieving objects in collections, Retrieval methods – HP Integrity NonStop J-Series User Manual

Page 106

background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Retrieving Objects in Collections

We have defined the major objective of collection classes as storing and retrieving objects. How
you retrieve or find an object depends on its properties. Every object you create has three
properties associated with it:

Type: for example, an

RWCString

or a double. In C++, the type of an object is set at

creation, and cannot change.

1.

State: the value of the string. The values of all the instance variables or attributes of an
object determine its state. These can change.

2.

Identity: the unique definition of the object for all time. Languages use different methods
for establishing an object's identity. C++ always uses the object's address. Each object is
associated with one and only one address. Note that the reverse is not always true,
because of inheritance. Generally, an address and a type

[8]

are both necessary to

disambiguate the object you mean within an inheritance hierarchy.

3.

Retrieval Methods

Based on the properties of an object, there are two general methods for finding or retrieving it.
Some collection classes can support either, some only one. The important thing for you to keep
in mind is which one you mean. The two methods are:

Find an object with a particular state. For example, test two strings for the same value. In
the literature, this is variously referred to as two objects testing isEqual, having equality,
compares equal, having the same value, or testing true for the == operator. Here, we refer
to the two objects testing equal as isEqual. In general, we need some knowledge of the
type of each object_or subtype, in the case of inheritance_in order to find the appropriate
instance variables to test for equality

[9]

.

1.

Find a particular object; that is, one with the same identity as the object being compared.
In the literature, this is referred to as two objects testing isSame, having the same identity,
or testing true for the == operator. We refer to this as two objects having the same
identity. Note that because value-based collection classes make a copy of an inserted
object, finding an object in a value-based collection class with a particular identity is
meaningless.

2.

This manual is related to the following products: