Browse Prior Art Database

A mechanism for upward object class casting in an object-oriented language.

IP.com Disclosure Number: IPCOM000015723D
Original Publication Date: 2002-Jul-01
Included in the Prior Art Database: 2003-Jun-21
Document File: 2 page(s) / 41K

Publishing Venue

IBM

Abstract

In existing object-oriented languages, object types (as differentiated from primitive types) allow themselves to be "cast" (changed from one class to another class) in only one direction: downwards, towards the class types they descend from. However, at times it is highly desirable to be able to cast a given object instance to a derived type. Most languages provide such an "upcasting" mechanism for primitive types (such as numbers stored in memory), but provide no facility to do so for objects, which can potentially encapsulate a variety of other types (object or primitive) at a number of different levels of visibility. In known object-oriented languages, it is possible to simulate an upcast by creating a new object of the desired upcast type, and then passing the old object to it's constructor method as a parameter. However, in known languages that provide visibility control, any values that are marked as "private" (i.e., access only within their class definition), some variables may not be mirrored. In addition, modifications made to the new child class will not be reflected upon in the original parent class. The present invention provides a mechanism to solve these problems, and open up new opportunities for object-oriented software design. The invention is a mechanism for providing upcasting features to object instances in an object-oriented language. The invention includes: 1) Representation of object instances by a series of linked ascendent objects, back to the root of the object tree, and 2) The definition of a new type of class initialization method, known as an "upcaster".

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 52% of the total text.

Page 1 of 2

A mechanism for upward object class casting in an object-oriented language.

  In existing object-oriented languages, object types (as differentiated from primitive types) allow themselves to be "cast" (changed from one class to another class) in only one direction: downwards, towards the class types they descend from. However, at times it is highly desirable to be able to cast a given object instance to a derived type. Most languages provide such an "upcasting" mechanism for primitive types (such as numbers stored in memory), but provide no facility to do so for objects, which can potentially encapsulate a variety of other types (object or primitive) at a number of different levels of visibility. In known object-oriented languages, it is possible to simulate an upcast by creating a new object of the desired upcast type, and then passing the old object to it's constructor method as a parameter. However, in known languages that provide visibility control, any values that are marked as "private" (i.e., access only within their class definition), some variables may not be mirrored. In addition, modifications made to the new child class will not be reflected upon in the original parent class.

The present invention provides a mechanism to solve these problems, and open up new opportunities for object-oriented software design. The invention is a mechanism for providing upcasting features to object instances in an object-oriented language. The invention includes:

    1) Representation of object instances by a series of linked ascendent objects, back to the root of the object tree, and

    2) The definition of a new type of class initialization method, known as an "upcaster".

Part (1) suggests a different mechanism for representing the data that includes an object in memory. Instead of a single structure containing all object variables for the object and all of it's ascendent objects, an object is represented by a linked-list of structures from the current object, extending back to the root object, each storing only the object/class variables for the given object. For example, given the object classes: Class A (containing NUMBER, NUMBER, NUMBER) and Class B, derived from A (which contains a pointer to a string object)

Instead of representing instances of B as a single unit containing:

(NUMBER), (NUMBER), (NUMBER), (POINTER TO STRING)

It would be represented in memory as:

(POINTER TO STRING) (POINTER TO CLASS A DATA STRUCTURE)

(NUMBER), (NUMBER), (NUMBER) <-- class A's data st...