Class DataObject() Foundation

Class function of the DataObject class.

Description

The DataObject class provides objects with dynamic member and dynamic method support. DataObjects are designed to serve as a universal and lightweight transport mechanism between the different tiers of an application.

Using DataObjects is like using objects of any other class. However, unlike ordinary objects whose state and behavior remains static as declared in the class, members and methods can be added dynamically to a data object after the instance object is created. This is done by by sending :new() to a DataObject class object.

Class methods
:new()
Creates an instance of the DataObject class.
Definition
:defineMethod()
Defines a dynamic method.
Overridden, derived from Abstract
:classDescribe()
Reflects the class definition.
:getNoIVar()
Handles access to instance variables.
:setNoIVar()
Handles assignment to and adding of instance variables.
:noMethod()
Handles calls to undefined methods.
Copying and Merging
:copy()
Creates a dependent shallow copy of this instance
:merge()
Merges exported member variables from another object into this instance.
Examples
Using DataObjects
// Basic usage patterns of data objects. 
// 
PROCEDURE MAIN 
 LOCAL oDO 

 oDO := DataObject():New() 

 /* Explicit check for a member using IsMemberVar(), 
  * and access of a non-existing member 
  */ 
 ? IsMemberVar(oDO, "lastname" )  // N 
 ? oDO:LastName                   // NIL 

 /* Add a member implicitly by value assignment, 
  * the check for a member and output its value 
  */ 
 oDO:LastName := "Picard" 
 ? IsMemberVar(oDO, "lastname" )  // Y 
 ? oDO:LastName                   // "Picard" 

 /* Use DataObject as dictionary 
  */ 
 oDO:setNoIVar( "accept-language", "en-us" ) 
 ? oDO:getNoIVar( "accept-language" ) // "en-us" 

 /* Define a method via code block, execute 
  * the method 
  */ 
 oDO:DefineMethod( "print" , {|oSelf|QOut("Hello "+oSelf:LastName)} ) 
 oDO:print()                      // "Hello Picard" 

 /* Add another member, redefine an existing 
  * method. Now implement the method using a 
  * function. Execute the method. 
  */ 
 oDO:FirstName := "Jean-Luc" 
 oDO:DefineMethod( "print", "displayname" ) 
 oDO:print( "," )                      // Jean-Luc, Picard 

RETURN 

/* A regular Xbase++ function. If used to implement a 
* dynamic method of a DataObject, the first parameter 
* passed to the function always is the DataObject 
* itself. 
*/ 
FUNCTION DisplayName(oSelf, cSeparator ) 
 ? oSelf:FirstName+cSeparator+" "+oSelf:LastName 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.