Navigating a Vision Database

Describing an Object

All objects respond to the message whatAmI by returning the name of their class as a string. For example:

  3 whatAmI
returns the string "Integer" and:
  "3" whatAmI
returns the string "String". All objects have a default way in which they print depending on their class. By default, an object will print its whatAmI value. Many classes redefine the print message to display more specific information about the object. For example, numbers and strings display their actual value in response to the print message:
  3 whatAmI printNL ;              #-   Integer
  3 printNL ;                      #-           3
  (3 + 3) whatAmI printNL ;        #-   Double
  (3 + 3) printNL ;                #-        6.00
  "3" whatAmI printNL ;            #-   String
  "3" printNL ;                    #-   3
If you do not terminate your request with a ';' character, the print message is automatically sent to the object returned by the request. Therefore:
  "19951231" asNumber asInteger asDate
automatically prints the object returned, in this case the Date object representing December 31, 1995. You can confirm that this is a date object using:
  "19951231" asNumber asInteger asDate whatAmI

The properties code and creationDate are defined for all objects. The code normally contains a string that identifies the object. The creationDate contains the date that the object was created. For example:

  Named Currency US
  do: [ whatAmI print: 30 ;
        code print: 10 ; 
        creationDate printNL ;
      ] ;

Note that the code value may not be unique and both properties can have an NA value. For example, instances of many of the built-in classes such as Number and String do not have these property values set. Although any method can initialize and reset these values, these properties are usually updated as part of the instance creation process.

The message displayInfo is defined to display an object's class name and value followed by a carriage return. Some classes, such as Entity redefine this message to display additional information. For example, the expression:

  Named Currency US displayInfo ; 
displays the code and name of the object representing the US currency.

The message profile is defined to display a descriptive report for an object. Some classes, such as Entity redefine this message to display additional information. For example, the expression:

  Named Currency US profile ; 
displays a descriptive report about the object representing the US currency.


Class Information

The message showInheritance can be sent to an object to see the classes in its hierarchy. For example, the expression:

  Integer showInheritance
displays the following:
   ***  Inheritance Map For Class: Integer  ***

   Object
     |
   Ordinal
     |
   Number
     |
  Integer   <===== YOU ARE HERE

Note that you can send the showInheritance message to any object. The expression 3 showInheritance is identical to the expression Integer showInheritance.

If you send the showInheritance message to a class that has subclasses, each subclass will be displayed recursively. The expression:

  Object showInheritance
can be used to display all the classes in your Vision database.

All objects respond to the message instanceList by returning an object containing the list of all instances in the recipient's class. The expression:

  Currency instanceList 
returns the list of instances in the class Currency. The expression:
  Currency instanceList do: [ displayInfo ] ;
displays the code and name of each currency instance. The masterList message has been defined to return the non-default, base object instances associated with a class. For example, the expression:
  Currency masterList do: [ displayInfo ] ;
will not include the default currency instance.

You can write a method that executes the displayInfo message for each instance in the class. For example:

  Entity defineMethod: [ | displayInstances | 
     ^self masterList do: [ displayInfo ] ;
  ] ;
To run this method for any Entity subclass, use:
  Currency displayInstances


Message Information

Several messages are available to display some or all of the messages to which the instances of a particular class can respond:

Message Definition
showMessages Displays all the messages defined for the object's class.
showMessagesX Displays messages defined for the object's class and any of its super classes excluding Object.
showProperties Displays all fixed and time series properties defined for the object and any of its super classes.
showMessagesDefining: string Displays all classes that have defined the message identified by the supplied string.
showMessageNamesContaining: string Displays all messages that contain the supplied string as part of the message name.
showMessagesUsing: string Displays all messages that contain the supplied string as part of its method definition.
showMethodsUsing: string Displays the actual method implementations that contain the supplied string as part of its definition.

All objects respond to these messages. Two instances of the same class will respond identically to any of these messages. Samples using these messages are available. Note that the "show" messages only reflect messages that have been committed to the database. If you want to include messages that have been defined during your session, use the messages: displayMessages, displayMessagesX, and displayProperties.


Top-Level Environments

The class Environment is used to keep track of the various object spaces that have been created. Three types of object space have been defined: DB spaces are used to store external database classes and methods for updating them; DBA spaces are used to store tools for managing various aspects of the Vision database; User spaces are used to store private user information.

You can access data stored in another object space independent of your top-level environment. The expressions:

  Environment User id           #  Environment User at: "id" .
or
  Environment DBA id            #  Environment DBA at: "id"  .
or
  Environment DB id             #  Environment DB at: "id" .
can be used to navigate to the top level of a private user, general administration or database space. The supplied id can be the identifier used to create the space or the space number. The object returned is the top-level of that space. As a result, any messages defined for that space can be accessed. For example, the expression:
  Environment DBA at: "5" . displayInfo
displays:
  Object Space Number:         5
  This Space Contains: Schema Management Tools
  Shared Access Via: Environment DBA Schema

To access a list of all the top level spaces created after object space 3, use the expression:

  Environment MaintenanceTools spaceList
This returns a list of all the top level environments. You can use this list to generate a report describing all spaces. For example:
  Environment MaintenanceTools spaceList
     do: [ number print: -5 ;         #- object space number
           whatAmI printNL ;          #- full access path
         ] ;


Object Identity

Several useful techniques are available to help determine the identity of any object.

A separate "is" message has been defined for every class in the database. For example, the expression 3 isInteger returns the value TRUE and the expression "xyz" isInteger returns the value FALSE. To determine if an object belongs to a particular class, you can send it an appropriate "is" message. For example:

 !value <- myObject isNumber
      ifTrue: [ myObject ] 
     ifFalse: [ 100 ] ;

The following relational operators can be used to determine if two objects are identical or equal:

Message Definition
= object Returns TRUE if recipient is equal to (has the same value as) the supplied parameter.
== object Returns TRUE if recipient is identical to supplied parameter.
!= object Returns TRUE if recipient is not equal to supplied parameter.
!== object Returns TRUE if recipient is not identical to supplied parameter.

For most classes the = and the == messages return the same value. For the ordinal classes (i.e., Number, Date, String), these messages return different results. For example, the integer 3 is equal to the double 3.0 because they have the same value. The integer 3 is not identical to the double 3.0 because they are not the same object. Therefore:

  3 = 3.0
returns TRUE and:
  3 == 3.0
returns FALSE. The = and != messages can be redefined for other classes as appropriate. Although you could redefine the == and !== messages, this is not normally done.

One common mistake when working with object identity occurs when an extended object is compared to an unextended object. Although the underlying objects may be the same, these objects will not be equal or identical. The message asSelf can be used to strip any extensions from an object. It is often useful to send this message to the recipient and parameter objects prior to performing any equality tests. For example:

  Named Currency US = (Named Currency US extendBy: [ !x ] )
returns FALSE, whereas:
  Named Currency US = (Named Currency US extendBy: [ !x ] ) asSelf
returns TRUE.

Related Topics