Vision Class: Object

Overview

The Object class is a direct or indirect super class of all other classes in the database. Any message defined at Object is applicable to all objects. Any subclass can redefine the behavior of a message defined at the Object class. You do not normally create instances of the class Object directly. When you create instances in another class, a new instance is created in each of that class' super classes including Object.

The major subclasses of Object are:

  Object
      Boolean
      DateRange
      Dictionary
      Entity
      Function
          Block
          IndexedList
          List
          TimeSeries
      Ordinal
          Date
          Number
          String
      ToolKit
          OpenVision
          Schema
          UserInterface
     Undefined


Messages defined at Object are available to all objects in the database. The following tables summarize the most frequently used messages. They are described in more detail in later sections.

The following messages are used to access and display basic information about a specific object:

Message Definition
code String representing recipient's user-defined id
creationDate Date of recipient's creation
whatAmI String identifying recipient's class
print Display recipient using default format for its class
print: Display recipient using supplied format for
printNL Display recipient using default format followed by a new line
printNL: Display recipient using supplied format followed by a new line
displayInfo Display a line of summary information about recipient
profile Display a descriptive report about recipient

The following messages are used to evaluate programs, sending all statements to the recipient object:

Message Definition
do: [] Evaluate parameter in the context of recipient and return the recipient
send: [] Evaluate parameter in the context of recipient and return the result of evaluating parameter
extendBy: [] Evaluate parameter in the context of recipient and return a specialization of recipient that includes variables defined in parameter

The following additional messages are frequently used:

Message Definition
= Is recipient equal to parameter?
!= Is recipient not equal to parameter?
asList Convert recipient to a List containing one element
asSelf Return recipient stripped of any extensions
asString Convert recipient to a String
isNA Is recipient an instance of the Undefined class?
isntNA Is recipient not an instance of the Undefined class?
else: [ ] If recipient is NA evaluate parameter; otherwise, return recipient
elseIf:[] then: [] If recipient is NA evaluate parameter1; if it is TRUE, evaluate parameter2 otherwise, return recipient
ifTrue:[]ifFalse:[]else:[] If recipient is TRUE evaluate parameter1; if recipient is FALSE evaluate parameter2; otherwise, evaluate parameter3

The following messages are used to perform class-level operations and are normally sent to the default instance of a class:

Message Definition
createSubclass: Create a subclass of the recipient
instanceList List of instances in recipient's class
createInstance: Create instance in recipient's class
defineFixedProperty: Define fixed property in recipient's class
define: Define time series property in recipient's class
define:toBe: Define class constant in recipient's class
defineMethod: Define method in recipient's class
getMessage: Retrieve the MessageImplementationDescriptor in recipient's class for the message named by parameter
showMessages Display all messages defined directly for recipient's class
showMessagesX Display all messages defined for recipient's class and its superclasses
showInheritance Display the recipient's position in the class hierarchy


Object Characteristics

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. 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.

An object respond to the message whatAmI by returning the name of its class as a string. An object respond to the message classDescriptor by returning the instance of the class Schema ClassDescriptor that corresponds to the object's class.

All objects respond to the messages isNA and isntNA, returning a Boolean value. Unless an object is an instance of the Undefined class, the value returned by the isNA message will always be FALSE and the value returned by the isntNA message will always be TRUE.

Whenever a new class is created, the message isXXX (where XXX is the class name) is defined as a class constant for the new class and for Object. The value of the constant for the new class is TRUE and the value for the Object class is FALSE. These messages are automatically defined when you create new classes using the createSubclass: message. As a result, you can send messages such as isNumber, isString, isDictionary, and isList to any object. For example, the expression:

  3 isString
returns FALSE and the expressions:
  3 isNumber
returns TRUE.

Every Vision class has an instance which represents its default instance. The property defaultFlag is defined at Object and set to TRUE if the object is the default instance for the class. The messages isDefault and isntDefault return a Boolean based on the value of this property.

An object can be flagged for deletion without actually removing it from the database. The property deletionFlag is defined at Object and set to TRUE if the object has been flagged for deletion. The messages isActive, isntActive, isDeleted, and isntDeleted, return a Boolean based on the value of this property.

The message super returns the instance of the recipient managed by its parent class.


Display Messages

All objects respond to the messages print and print:. Many classes redefine these messages. By default, the print message displays the name of the object's class. The print: message provides you with control over the width of the printing format. The interpretation of the parameter depends on the recipient object's class. More information about printing rules is available.

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.


Evaluation Messages

It is often useful to send a number of messages to the same object. For example, you could request a number of values for the Canadian currency object using:

  Named Currency CAD code print ;
  Named Currency CAD name print ;
  Named Currency CAD usExchange printNL ;
The do: message can be used to "factor out" the repeated expression in the body of your program, in this case the Named Currency CAD. The previous example could be rewritten using:
  Named Currency CAD
  do: [ code print; 
        name print ; 
        usExchange printNL ;
      ] ;

The general form for the do: message is:

  object 
  do: [ expression1 ;
        expression2 ;
        #- ...
        expressionN ;
      ] ;

The do: message requires one parameter, a block containing the program to evaluate. All expressions inside the block are evaluated for the recipient object, the Canadian currency in the early example. After the block has executed, the do: message returns the recipient object.

The do: message is one of several messages that changes the context of the message execution. The send: message is identical to the do: message except that it returns the result of executing the block instead of the original object.

The general form for the send: message is:

  object 
  send: [ expression1 ;
          expression2 ;
          #- ...
          expressionN ;
          returnObject
        ] ;

For example:

  #--  Case 1: 'do:' returns the original object
  !result <- "xyz" do:
     [ printNL ;           #- print recipient
       count printNL ;     #- print count
       count               #- result of block
     ] ;
  result printNL ;          #- prints string "xyz"

  #--  Case 2: 'send:' returns the result of the block
  !result <- "xyz" send: 
     [ printNL ;           #- print recipient
       count printNL ;     #- print count
       count               #- result of block
     ] ;
  result printNL ;         #- prints 3 (the count returned)
In the first case, the variable result is assigned to the object returned by the do: message. Since do: returns the recipient object, the value of result is the string "xyz". Note that the result returned by the block is ignored in this situation. In the second case, the variable result is assigned to the object returned by the send: message. Since send: returns the result of evaluating the block, the value of result is the recipient string's count, 3.

The extendBy: message is similar to do: except that it returns the original object extended by the extra layer of messages defined within the block. The general form for the extendBy: message is:

  !newObject <- object extendBy:
      [ !variable1 <- expression1 ;
        !variable2 <- expression2 ;
        #- ...
        !variableN <- expressionN ;
        ^current define: 'ts1' ;
        ^current defineMethod: [ | m1 | whatAmI print ; ] ;
      ] ;

The variable newObject is an instance-level specialization of the recipient object. This object responds to all the variables defined by the block and inherits from the original object. For example:

  !result <- "xyz" extendBy:
     [ !countPlus1 <- count + 1 ; #- create a variable
       !countPlus2 <- count + 3 ; #- create another one
     ] ;
  result
  do: [ printNL ;                 #- print string xyz
        count printNL ;           #- inherited message prints 3
        countPlus1 printNL ;      #- extension message prints 4.00
      ] ;
The variable result responds to the message countPlus1 and any additional messages to which the original String object responds such as count.

The extendBy: message can define any number of new messages within the block. Any number of extendBy: messages can be applied in succession. Each extendBy: creates a new layer for resolving messages. Messages are resolved by searching from the last extension layer added backwards. For example:

  "xyz" 
     extendBy: [ !layer1 <- "this is layer 1" ] .
     extendBy: [ !layer2 <- "this is layer 2" ] .
     extendBy: [ !layer3 <- "this is layer 3" ] .
  do: [ count printNL ;
        layer1 printNL ;
        layer2 printNL ;
        layer3 printNL ;
     ] ;
Each application of the extendBy: message returns the prior recipient plus the new message. The final do: message accesses data from each of these extensions (layer1, layer2, layer3) and from the original object (count).

The messages asLocalContextFor: and extendedBy:asLocalContextFor: are defined at the class Object to provide a way to to extend the global environment with additional protocol. These messages are described in detail in conjunction with the magic word ^local.


Class and Instance Messages

A number of messages are defined for the class Object are used to create and manage classes and instances. These messages are summarized in the following tables.

The following messages are used to create new subclasses and are normally sent to the default instance of the class you wish to subclass:

Message Definition
createSubclass Creates and returns subclass of recipient
createSubclass: Creates and returns subclass of recipient, using parameter string to name the new class
createSubclass:at: Creates and returns subclass of recipient, using parameter1 string to name the new class and parameter2 to identify the class at which the new class should be named
initializeGlobalSubclassProperties Sets value in default instance and defines class methods and constants as part of the createSubclass process
basicSpecialized Primitive method to create and return subclass of recipient, without running any special initialization steps
newPrototype Primitive method to create a new prototype of recipient

The following messages are used to determine the recipient's class inheritance:

Message Definition
showInheritance Displays inheritance hierarchy of recipient
inheritsFrom: Is recipient a subclass of parameter?
isSuperClassOf: Is recipient a superclass of parameter?

The following messages are used to create new instances of a class:

Message Definition
createInstance Creates and returns a new instance in recipient's class
createInstance: Creates and returns a new instance in recipient's class, using parameter string to name the new instance
initializeGlobalInstanceProperties Sets initial values in new instance
basicNew Primitive method to create and return new instance of recipient's class, without running any special initialization steps
clusterNew Primitive method to create and return new instance of recipient's class, without running any special initialization steps used with some built-in classes to ensure that instances are clustered

The following messages are used to access the instances in the recipient's class:

Message Definition
instanceList Returns List of all instances in recipient's class
masterList Returns List of all non-default instances in recipient's class
activeList Returns List of all non-default instances in recipient's class that are not flagged for deletion

Many messages have been defined at the Object class to support a variety of database administration fucntions. Detailed information is available.


Message Management Messages

A number of messages are defined for the class Object are used to create and manage messages. These messages are summarized in the following tables.

The following messages are used to create and delete messages and are normally sent to the default instance of the class:

Message Definition
defineFixedProperty: Define fixed property named by parameter for recipient's class
defineFixedProperty:withDefault: Define fixed property named by parameter1 for recipient's class and set default value to parameter2
define: Define time varying property named by parameter for recipient's class
define:withDefault: Define time varying property named by parameter1 for recipient's class and set default value to parameter2
define:toBe: Define class constant named by parameter1 that returns value of parameter2
defineMethod: Define method for recipient's class using block provided as parameter
deleteMessage: Delete message named by parameter from recipient's class

The following messages are used to access and the display the messages defined for the recipient's class:

Message Definition
getMessage: Retrieve the MessageImplementationDescriptor in recipient's class for the message named by parameter
getMessages Return List of messages in recipient's class
showMessages Display messages in recipient's class
getMessagesX Return List of messages in recipient's class and its superclasses
showMessagesX Display messages in recipient's class and its superclasses
getMessagesDefining: Return List of messages in recipient's class hierarchy that define the message specified by parameter
showMessagesDefining: Display messages in recipient's class hierarchy that define the message specified by parameter
getMessageNamesContaining: Return List of messages in recipient's class hierarchy with names that contain the substring specified by parameter
showMessageNamesContaining: Display messages in recipient's class hierarchy with names that contain the substring specified by parameter
getMessagesUsing: Return List of methods in recipient's class hierarchy that use the substring specified by parameter
showMessagesUsing: Display names of methods in recipient's class hierarchy that use the substring specified by parameter
showMethodsUsing: Display implementations of methods in recipient's class hierarchy that use the substring specified by parameter
getMessagesInInheritancePath Return List of messages in recipient's class hierarchy
showProperties Display messages defined as properties in recipient's class
selectorList Primitive method to return list of strings representing messages defined for recipient


Object Identity Messages

The = and != messages compare the recipient and parameter objects for equality. The == and !== messages compare recipient and parameter object for object identity. For most classes the = and == messages and the != and !== 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.

The messages isEquivalentTo: and isntEquivalentTo: return TRUE (FALSE) if the recipient object is equal to (not equal to) the parameter. At the Object class, the isEquivalentTo: message is defined using = and the isntEquivalentTo: message is defined to return the opposite logical value. The isEquivalentTo: message can be redefined by subclasses to alter this comparison.

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.

The asBaseObject message returns the actual object that was created with the createInstance message. When it is sent to an extension of an object, it returns the same value that asSelf returns. When it is sent to a super instance of an object, it returns the original child object.


Object Constants

Several frequently used values have been defined as constants at the class Object. You can send these messages to any object to access the defined constant value.

Message Definition
NA Returns the Undefined value
FALSE Returns the boolean value FALSE
TRUE Returns the boolean value TRUE
earliestPossibleDate Returns the Date representing January 1, 0001
newLine Returns a String containing the new line character
newPage Returns a String containing the form feed character


Currency Messages

The Currency class is used to track exchange rate information between currencies. Several messages have been defined at the Object class to support the basic currency protocol for all objects:

Message Definition
baseCurrency Fixed property that stores the actual currency in which data values for the recipient are stored and accessed by default
currency Returns the current currency override if set, the baseCurrency otherwise
currencyFactor Returns the exchange rate between the base currency and currency override
setBaseCurrencyTo: Sets the base currency of the recipient to the currency specified by the parameter


General Access and Update Messages

Several messages have been defined at the Object class to support general access and update for all objects:

Message Definition
getPotentialChoicesForString: Returns List of objects in recipient's class that could be associated with parameter
validateInputString: Returns object in recipient's class associated with the supplied parameter
extract:forDateRange: Evaluates parameter1 block for recipient for each date in parameter2, returning the result as a TimeSeries
setProperty:to: Updates parameter1 with the value of parameter2 in recipient
updateTS:with: Updates time series indicated by parameter1 with the value of parameter2 in recipient

Related Topics