A mechanism for upward object class casting in an object-oriented language.
Original Publication Date: 2002-Jul-01
Included in the Prior Art Database: 2003-Jun-21
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".