Comparing One Object’s Structure with Another

Because it obtains information about the entire inheritance hierarchy of an object, Proteus can compare the structures of objects.

 

Comparing Object Structures

The hasStructureOf(otherObj) message returns an enumerator representing the comparison of the object being sent the message, and the otherObj passed as an argument. The enumerators have the following meanings:

 

Enumerator

Meaning

tautological

The objects are structurally the same object

equivalent

The two objects are instances of the same traits

contingent

The two objects are instances of the same traits, but differ in their directly-defined properties list.

trait

The object is a trait of otherObj

extension

The object is an extension of otherObj

shared

The objects share at least one trait

disparate

The objects have no traits in common beyond TadsObject

 

Comparing Object State Structures

The hasStateStructureOf(otherObj) message returns the same enumerator as the hasStructureOf() message, but the analysis only involves the state structure of the objects.

 

Comparing Object States

The hasStateOf(otherObj, [bypass]) message returns true if the state of the object being sent the message is the same as the state of otherObj passed as an argument. If the two object’s states are not the same then the message returns nil. This is done by first comparing the values of the properties of the state structure of this object with the values for those same properties of otherObj, and then by comparing the values of the properties of the state structure of otherObj with the values for those same properties in this object.

 

Note that this message does not compare the state structures of the two objects. It is possible for two objects to have the same state, while having differing state structures.

 

Equality of Objects

When Proteus addresses the issue of the equality of two objects it is not concerned with the tautological relationship objectA == objectA, but instead defines equality as follows:

 

  • If the objects are dynamically-created or anonymously-defined, the first symbolic ancestor lists of the two objects are equal.
  • The message objectA.hasStateOf(objectB) returns true

 

Using these rules, the following condition are then true:

 

       ((objectA == objectA.createInstance()) != true)

(objectA.equals(objectA.createInstance()) == true)

 

The Delta of Two Objects’ States

When comparing the states of two objects it can be desirable to retrieve only those properties and values that are different. This can be done by sending any object the message getStateDelta(otherObj, [bypass]). The list returned is of the format:

 

[[propertyA [ thisObjValue, otherObjValue], [propertyB [ thisObjValue, otherObjValue], …]

 

The list is produced by traversing the entire inheritance hierarchy.

 

The message takes the following arguments:

 

  • otherObj: the object to which this object’s state is to be compared.
  • bypass: a variable argument list of any properties that are to be excluded from the comparison.

 

The object state delta can be a very powerful tool in analyzing object snapshots (pictures of an object’s state at a given point in time).

 

 

This file is part of the TADS 3 Proteus Library Extension

Copyright © 2001-2004 Kevin Forchione. All rights reserved.