Method and system for implementing software objects5978582Abstract A system for implementing software objects using an object-prototype model. Objects are defined as collections of properties, each having a unique property name. A collection of property names defines a "shape." The use of shapes frees the representation of an object in memory from the order in which the properties of the object are declared. Methods are defined independently of objects and are applicable to a specified shape, rather than to objects that are derived from a class in which the method is defined. Methods can be applied to any object that has the specified shape or that has a superset of the properties defining the specified shape, regardless of the place of the object in any inheritance hierarchy. The definition of a shape can also include additional selection criteria, such as restrictions on the values of properties, so that the application of a method can be restricted to objects satisfying the specified criteria. The properties of objects can be divided into subgroups representing different aspects of the object and different subgroups of an object can be inherited from different parent objects, based upon either a has-a or an is-a hierarchy. The shape of an object is determine by all of its properties and is not confined by subgroup boundaries. Claims We claim: Description TECHNICAL FIELD
______________________________________
Behavior for shape of Caption, FontSize
ChangeCaptionFontSize (NewFontSize)
{
FontSize = NewFontSize
}
}
______________________________________
The ChangeCaptionFontSize method could, therefore, operate on Button object 102 (FIG. 5) because Button object 102 has a shape that is convertible into, i.e., is a superset of, the shape of the ChangeCaptionFontSize method. In contrast to previous programming systems in which methods were defined as part of a class and were applicable only to objects of the defining class or objects derived from the defining class, the methods of the present invention operate on any object having the required properties, regardless of the derivation of the object. Restrictions on Behavior The present invention also allows restrictions on behavior. Such restrictions limit the objects to which the behavior applies. Behavior may be limited based upon, for example, the properties values or other aspects of an object. For example, methods DoubleFontSize and HalfFontSize could be defined to operate on objects having a shape FontSize and Visible, but only if the Visible property has a value of TRUE. The declaration would appear, for example, as:
______________________________________
Behavior for Shape of Font, Visible satisfying
Visible = TRUE
DoubleFontSize ( )
{
Font = 2 * Font
}
HalfFontSize ( )
{
Font = Font / 2
}
}
______________________________________
Tests to determine whether a property meets the restriction are applied when the method is called. The restrictions on the applicability of behavior can be applied to the object as a whole, rather than to the properties of the object. For example, a method may be defined to operate only on a specified object or only on an object that is contained in or derived from a specified object. Implementing Behavior Methods in the present invention can be organized globally or in association with objects. Either of these two techniques for organizing methods can be used with any of the three techniques described below for storing property values. If methods are organized globally, methods are stored independently of objects, for example, in a central methods table. When a method is called with an object as its argument, the system will compare the shape of the object with the shape of the method. If the shape of the object is the same as or convertible into the shape of the method, the method restrictions will then be checked with respect to the object being passed. If the restrictions are satisfied, the method will be executed on the object. Although methods are organized globally in this embodiment, the ability to include restrictions on methods allows the applicability of methods to be arbitrarily limited, for example, to particular objects or to objects in a particular container. Method execution is described in more detail below. In embodiments in which methods are organized in association with objects, when behavior is declared, the shape of the new behavior is compared with the shapes of existing objects. References to the methods comprising the behavior are added to each existing object that has the shape of the method or a shape that is convertible into the shape of the method. Methods are thus associated with objects, and only methods associated with the object can act on the object. Either a copy of the method itself can be stored with each object or a reference to a single copy of the method can be stored. Because methods are checked for compatibility before being associated with each object, it is unnecessary to check for compatibility when a method is invoked. If the behavior declaration includes restrictions, it is still necessary to check whether the restrictions are satisfied because the restrictions can be based on parameters, such as property values, that can change during program execution. The ability to define methods independently from objects and to define restrictions on behaviors provides an advantage over prior art programming systems. Share Tables Besides maintaining property name table 108, a system of the present invention also maintains a shape table 134, shown conceptually in FIG. 8. Shape table 134 includes an indexed entry 136 for each of the different shapes of declared objects and methods. Returning to FIG. 4, step 138 shows that when a new object is declared, the system compares the shape of the new object with existing shape entries 136 of shape table 134 to determine whether the shape of the new object matches an existing shape. If the shape of the new object does not match an existing shape, step 140 indicates that the new shape is added to shape table 134 and indexed with a corresponding new shape index value 142. For example, Button object 102 of FIG. 5, which has a shape 152 shown in FIG. 8, is indexed as the first shape 136 in shape table 134. Properties 154 of shape 152 are arranged in canonical order, that is, in order of their indices in property name table 108, thereby eliminating the necessity of checking permutations of property names when searching the shape table for matching shapes. Maintaining shape table 134 using property index numbers 122 instead of property names and maintaining the property name table index numbers 122 in canonical order also greatly reduces the look-up time required in determining convertible shapes and mapping properties. Besides the property name table index number 122 corresponding to property name table 108, each property in a shape also has a within-object property number 156 corresponding to its position within the shape. If a second object, such as BigButton object 158 (FIG. 9), is defined to have the same properties as a first object, such as Button object 102, no additional entry would be created in shape table 134 because no new shape has been created. On the other hand, when a new object, such as ColorButton 160 (FIG. 10), is declared as having properties that define a unique shape 162 (FIG. 8), the system will determine that the new shape (Visible, Color, Bounds, Caption, and FontSize) does not correspond to any existing shape and will create and index a corresponding new entry 136 in shape table 134. Similarly, when behavior is declared as being applicable to a specified shape, the shape of the behavior is compared to existing shapes in shape table 134 and is added to shape table 134 if not already present. The term "within-object property number 156" is used generally to refer to any "within-shape" property order, including the "within-method" property order within a method. After creating new shape entry 136, step 170 of FIG. 4 shows that the system compares the new shape with each of the existing shape entries 136 to determine whether the new shape is convertible to any of the existing shapes. The new shape is convertible to an existing shape if the properties of the new shape are a superset of the properties of the existing shape, i.e., if the new shape includes all of the properties of the old shape and at least one additional property. The existing shape is, therefore, a projection of the convertible new shape. The intersection of the set of properties of the existing shape and the set of properties of a convertible new shape is, therefore, the set of properties of the existing shape. If the new shape is convertible to an existing shape, step 172 shows that a convertibility entry 174 is created in the shape table entry 136 for the new shape indicating the existing shape to which the new shape can be converted. If the new shape can be converted into more than one of the existing shapes, shape table entry 136 for the new shape will include a convertibility entry 174 for each existing shape to which the new shape can be converted. Step 176 shows that a map table 178 is created that shows which of the properties of the new shape correspond to each of the properties of the existing shape. Shape table 134 is shown without a right edge to indicate that the number of existing shapes to which the new shape is convertible is not arbitrarily limited and may increase as new shapes are defined. For example, shape table 134 (FIG. 8) shows that shape four is a superset of shapes one and three and is, therefore, convertible into shapes one and three. Shape table 134 also includes, in some embodiments, map tables 178 indicating how to transform shape four into shape one or shape three. Methods that are defined to operate on shapes one and three could then operate on an object of shape four after the object is transformed in accordance with map tables 178. For example, the first property of shape four and of shape three is Visible, so the first property of shape four maps to the first property of shape three. The second property of shape three is FontSize, which is the fourth property of shape four, so the fourth property of shape four maps to the second property of shape three. The numbers used in map tables 178 are the within-object property numbers 156. Methods can, therefore, refer to properties internally by their within-shape property numbers, which is more efficient than referring internally to property names 124 or property name table index numbers 122. After all the existing shapes to which the new shape can be converted are listed in new shape entry 136 of shape table 134 and the corresponding map tables 178 are created, step 188 shows that the system performs the reverse process, that is, it analyzes the existing shapes to see whether the new shape is a subset of any of the existing shapes. If so, step 190 shows that the new shape is added as a convertible entry 174 to the list of convertible shapes for the existing shape, and step 192 shows that a corresponding map table 178 is created. The existing shapes in shape table 134 are thus updated as each new shape is added. Shape table 134 and property name table 108 provide structure for a programming application using the present invention. The tables do not, however, contain actual objects. An object of the invention is stored in memory as an object memory structure 198 as shown in FIG. 11. Object memory structure 198 consists of a shape index 200 and property values 202. The shape index is a reference to an indexed entry in shape table 134. In some embodiments, object memory structure 198 also includes behavior 204, which comprises references to the methods that are applicable to the object. Data Organization, First Embodiment In a first embodiment, shown in FIG. 12, property values 202 are stored in an object memory structure 206 in ascending order of the property name table index number 122 of each property. Each property value 202 has the same length, typically 32 bits, and the property values 202 collectively constitute a property value vector 208. Shape table 134 lists the properties of the object (by property name table indices), and the data contained in property value vector 208 corresponds in order one-to-one with the listed properties of the object. Some or all of the property value 202 entries in property value vector 208 may be pointers to the values, rather than actual values. Property value vector 208 allows the use of an index to access property values within object memory structure 206. Using an index has the advantages of being simple to implement and relatively fast for accessing values, but this technique requires that the data for each property be of equal, or at least predetermined, size so that the system can determine where in the object memory structure 198 the datum for each object begin. Using pointers in place of actual data in property value vector 208 adds flexibility by allowing the actual data to be of different sizes and is used in inheritance as described below. In practice, object memory structure 206 contains primarily pointers, with actual data being stored typically for only short data types, such as small integers. A code in the memory location in the datum field can be used to indicate whether the datum in that field represents a value or a pointer. It is also possible to implement this embodiment using flags to indicate the beginning and end of the data field for each property. FIG. 13 shows a schematic of a preferred implementation of a shape table 134 used in the first embodiment of the invention, which uses an object memory structure 206 including property value vector 208. Each indexed shape entry 216 in a shape table 218 includes two pointers: a first pointer 220 points to a property list 222 of properties and a second pointer 228 points to a convertibility list 230 of shapes to which the entry shape can be converted. Each property list 222 includes the properties that define the shape. Property lists 222 use property name table index numbers 122 from property name table 108, rather than actual property names 124. As described above, property names are not typically used once the property name 124 has been entered in property name table 108 and a property name table index number 122 has been assigned. Property list 222 is in ascending order of the property name table index numbers 122, regardless of the order of the properties in the programmer's declaration of the corresponding object or method. Each entry in convertibility list 230 of convertible shapes consists of a shape index number 232 and a pointer 234 to a map table 244. Map table 244 is a list of the within-object property numbers 156 of the shape entry 136 that corresponds to the properties of the shape to which shape entry 136 is being converted. The within-object property numbers 156 used in list 230 are the sequential numbers of properties in the shape entry, not the property name table index numbers from property name table 108. Examining the first indexed entry 216 of shape table 218 as an example, FIG. 13 shows that pointer 220 in the first indexed entry 216 points to a list 222 including properties 1, 2, 3, and 4 (referring to properties Visible, Bounds, Caption, and FontSize, respectively, from property name table 108 (FIG. 7)). Pointer 228 points to a convertibility list 230 that has only one entry, 3, which refers to the third shape in shape table 218, and a pointer 234 to map table 244. Map table 244 includes the numbers 1 and 4, indicating that the first and fourth properties of shape one correspond to the first and second properties of shape three. Continuing down the indexed entries 216 of shape table 218, shapes two and three also include pointers 220 to property lists, but because shapes two and three are not convertible into other shapes, pointers 228 to their convertible tables are set to NULL. Convertibility list 230 corresponding to shape four includes two entries. The first includes a shape 200 having a value of 1 and a pointer 234 to a corresponding map table 244 that includes within-object property numbers 1, 2, 3, and 4. The other entry includes shape index three and a pointer 234 to a corresponding map table 244 including within-object property numbers 1 and 4. Data Organization, Second Embodiment A second structure for storing and accessing property values of an object uses an object memory structure 246, exemplified in FIG. 14, having a property value storage area 248. In this embodiment, different property values 202 stored in property value storage area 248 can be of different lengths. Thus property values 202 do not constitute a vector as in the first embodiment and are not accessed by an index into property value storage area 248. Each named property, however, will have the same storage length in property value storage areas 248 of different objects. FIG. 15 shows a shape table 250 used in this embodiment. Shape table 250 is similar to shape table 218 shown in FIG. 13, but also includes for each different shape a method pointer vector 252, consisting of sets 262 of pointers. Each set 262 corresponds to a property in property list 222 of the shape and includes a pointer 264 to a method that gets the corresponding property value and a pointer 266 to a method that sets the value of the corresponding property of the object. Such methods are referred to herein as "get and set" methods. The get and set methods keep track of the exact location and size of the property values in object memory structure 246 for objects having the corresponding shape, thereby allowing use of property values of different sizes. Pointer sets 262 are stored in order of the property name table index numbers 122 of the properties upon which their methods operate, typically in ascending order of the property name table index numbers 122. Pointer 228 of each entry 216 points to a convertibility list 274 having entries 276, each of which includes a shape reference 278 and a pointer to a conversion method vector 282. The conversion method vector 282 includes a subset of the pointer sets 262 in the corresponding method pointer vector 252, the subset corresponding to the properties contained in the shape to which the shape entry 216 is being converted. For example, FIG. 15 shows that pointer 228 of the fourth shape entry 216 points to a conversion method vector 274 that has two entries 276, one corresponding to shape one and one corresponding to shape three. The property list 222 corresponding to shape three shows that shape three includes two properties, Visible (property name table index number 1) and FontSize (property name table index number 4). The corresponding conversion method vector 282, therefore, also has two entries, each comprising a set 262 of pointers 264 and 266. If, for example, a method having shape three is passed an object of shape four, the system would access the FontSize property of the object, which has a within-shape property number of two in the method shape, by using the second set 262 of pointers in the conversion method vector 282 that converts from shape four to shape three. In this embodiment, there is one object memory structure 246 for each object and one table of get and set methods for each shape. This second embodiment is somewhat analogous to a virtual function table in C++, but with the methods for each shape are indexed by within-object property number 156 rather than by a virtual function number. In one variation of this embodiment, the get and set methods could be combined into a single method and an additional argument could be passed to the method to indicate whether the property is to be set or retrieved. In yet another variation, the vector of pointers to get and set methods can be replaced with a pointer to a single get and set handler method that, when passed the object and the within-object property number, accesses the appropriate property value. In this case, the property value to be returned is determined within the get and set handler method, for example, by using a "switch" statement, rather than being determined before the method call and then calling the appropriate method. In the two embodiments described above, property values are accessed by an index value into a vector, either of values or of methods. A third embodiment accesses property values using a run-time method table similar to those used in object-oriented languages such as Smalltalk. In this embodiment, all properties are treated as methods that set or return the property. Data Organization, Third Embodiment This third embodiment uses an object memory structure 288 as shown in FIG. 16. Each object memory structure 288 in this embodiment includes a shape index 200 indicating its shape with reference to a shape table, behavior 290, and property values 292. Behavior 290 comprises a searchable method table that includes references to methods that get and set each of the properties of the object, as well as references to other methods that operate on the object. This embodiment differs from the previously described ones in that the methods that get and set property values are associated with the object, rather than associated with the shape. That is, there is one set of get and set methods for each object, rather than one set for all objects having the same shape. The data within each object memory structure 288 is, therefore, not required to be in any particular order because the get and set methods can be different for different objects. FIG. 17 shows a simplified shape table 296 used in the third embodiment. Each shape entry 298 includes a pointer 300 to a property list 302 and a pointer 308 to a convertibility list 310. Convertibility list 310 comprises only a list of shapes to which the shape of the entry can be converted and does not include a pointer to a map table. Property list 302 includes property name table index numbers 122 that refer to property name table 108 (FIG. 7). It is not necessary to indicate how to convert between shapes. As will be described in more detail below, properties are accessed by method calls that refer to property name table index numbers 122, rather than to within-object property numbers 156. Properties in shape table 296 are still maintained in canonical order using index values 122 from property name table 108 so that the entries in shape table 296 can be compared to the shape of newly declared objects, without concern for permutations of property order. Creation and Execution of Methods The details of method execution will vary depending upon which of the three data organization embodiments described above is used, as well as which of the two techniques is used for organizing methods, i.e., through a global method table or in association with objects. The execution of methods will be described with respect to an example method, DoubleFontSize, to illustrate the principles of the present invention. FIG. 18 shows the steps entailed in creating behavior in systems that use either of the first two data organization embodiments described above. Step 316 shows that first behavior is declared, for example:
______________________________________
Behavior for Shape (Visible, FontSize)
satisfying Visible = TRUE
DoubleFontSize ( )
FontSize = 2 * FontSize
}
End
______________________________________
Step 318 shows that shape table 134 (the form of the shape table will depend upon which of the embodiments described above is being implemented) is searched to determine whether the shape of the behavior is new. Step 320 shows that if the behavior does not correspond to one already in the shape table, the new shape is entered. In this example, the shape (Visible, FontSize) is already indexed in shape table 134 as shape number three. Next, step 330 shows that the system determines from shape table 134 that shapes one and four are convertible to shape three. Step 332 shows that the system then finds all objects having shapes three, one, or four and adds a reference to the DoubleFontSize() method to the behavior list of each object. In an embodiment in which methods are not associated with objects, steps 330 and 332 are not performed. The newly declared method is instead added to a global method table. Continuing with the above example, a ColorButton object may be declared as follows:
______________________________________
Object ColorButton
HAS
Visible
bool
Bounds RECT
Caption
text
FontSize
int
Color int
END
END
______________________________________
FIG. 19 is a flow chart illustrating the steps that take place in invoking a method on an object, such as ColorButton. Step 334 shows that the process begins when a method is invoked. For example, a method called DoubleFontSize could be called to operate on the object ColorButton by a line of code such as ColorButton.DoubleFontSize(). As shown in step 336, a compiler then typically converts the original method call to a modified method call to the DoubleFontSize method, the modified call having as an "invisible parameter" a reference to the ColorButton object and appearing, for example, as DoubleFontSize(ColorButton). In an embodiment in which methods are not associated with objects, step 338 shows that the shape of the object upon which the method is invoked is determined from the object memory structure 198 (FIG. 11) of the object. Step 342 shows that the global method table is searched to find a method having a method name that matches that of the invoked method. When a matching method name is located, step 344 shows that the shape of the object upon which the method is invoked is compared to the shape of the located method. If the shape of the object is the same as or convertible into the shape of the method, the process of executing the method will continue. Otherwise, step 342 is repeated, i.e., the global method table will be searched to locate another matching method name. In an embodiment in which methods are associated with objects, a method call causes the method table associated with the object to be searched. All methods contained in the method table associated with the object have already been checked for compatibility with the object, so no additional shape check is required. After locating in a method table a method having a method name matching the invoked method name and being compatible with the object upon which the method is invoked, step 350 indicates that a reference to a means for converting from the object shape to the method shape is attached as an invisible parameter to the method call. A conversion means is required because, in the first two embodiments, the compiler has typically reduced references to property names 124 and property name table index numbers 122 in a method or object down to a within-object or within-shape property number 156. In the first embodiment for data organization described above, the means for converting between shapes is map table 244 (FIG. 13). In the second embodiment for data organization described above, the means for converting between shapes is conversion method vectors 282 (FIG. 15). If the shape of the method is the same as the shape of the object, an identity mapping is used. In the third embodiment for data organization described above, property values are referenced by a run-time look-up, rather than by a within-object property number, so no additional means is required to convert between shapes. After a method of an appropriate shape is located, step 358 indicates that the object is tested for compliance with any "satisfying clauses," i.e., restrictions on the method. In the DoubleFontSize example, the value of the property Visible is checked to determine whether it is TRUE. The technique by which the value of a property is obtained is described below and will vary depending upon which data organization embodiment is used. If any restriction is not satisfied, step 342 is repeated and another method is sought. If restrictions are satisfied, step 360 indicates that the method is executed with the passed object. Accessing Properties During method execution, it is necessary to access values of properties of objects, either to retrieve or to set the value. The technique used to access property values will depend upon how the property values are stored. In the DoubleFontSize method example above, method execution requires obtaining the value of the FontSize property, multiplying it by two, and then storing the result as the new value of the FontSize property. In the shape of the DoubleFontSize method, FontSize is the first property and Caption is the second property. When the DoubleFontSize method is compiled, the compiler will typically replace references to FontSize with a reference to Property 1 and references to Caption with a reference to Property 2. This substitution increases execution speed. In the ColorButton object, however, the first and second properties are Visible and Bounds, and FontSize is the fourth property. During execution, the method uses the map table 244 or conversion method tables 282 to access the correct properties in the ColorButton object for use in the DoubleFontSize method. First Embodiment In the first embodiment for data organization described above, which stores property values in property value vectors 208, the value of the FontSize property is accessed as shown by the flow chart of FIG. 20. Step 364 indicates that the process begins when the system requests the value of a property of an object that is passed to the method. Properties within objects are typically referred to by their within-object property number. As described above, a reference to the map table of the object, i.e., ColorButton, was included as an invisible parameter of the method call. Step 366 shows that the map table 244 of shape table 218 (FIG. 13) is consulted to determine how to convert from a ColorButton object of shape four into shape three. Map table 244 for converting from shape four to shape three comprises a list having as elements one and four, indicating that the first and second properties of shape four correspond to the first and fourth properties in an object of shape one. The DoubleFontSize method, therefore, accesses the fourth property of the object ColorButton to obtain its FontSize property. Step 368 shows that fourth entry in property value vector 208 is retrieve. Step 370 shows that the retrieved datum is checked, for example by reading a flag bit, to determine whether the datum corresponds to a data value or to a pointer. Step 372 shows that, if the retrieved datum is a pointer, the pointer is followed to retrieve the actual datum value of FontSize. Step 374 shows that the property value is retrieved or set. Execution of the DoubleFontSize method continues with multiplying the retrieved value of FontSize by two. The result is then stored as the new value of the FontSize property in the Button object. Storing a property value entails accessing map table 244 to determine the within-object property number of the property value to be stored and either writing the new value to the correct location or writing a pointer to the new value to the correct location. If the shape of the method is identical to the shape of the object, no conversion is required and an identity map table is used. Second Embodiment FIG. 21 is a flow chart showing the steps used to access properties in the second embodiment for data organization, in which references to get and set methods are associated with each property in shape table 250 (FIG. 15). As described previously, a method call in this embodiment includes two invisible parameters: a SELF reference to the object being passed and a reference to a means for converting between the shape of the object and the shape of the method. In this embodiment, the means for converting is the corresponding conversion method vector 282 for converting from the shape of the object to the shape of the method. The entries in conversion method vector 282 are pointers to the get and set methods for each property of a first shape listed in the order of the properties of a second shape. Step 382 shows that a reference to the corresponding conversion method vector 282 is obtained from the function call. Step 384 shows that the within-shape property number 156 (FIG. 8) from the method is used as an index into the conversion method vector 282 to determine the appropriate set 262 of pointers 264 and 266 to methods for accessing the property values in object memory structure 246. Step 386 shows that the appropriate method to get or set the property value is executed. For example, in conversion method vector 282 for converting from shape one to shape three, the entries comprise pointers to get and set handlers for the Visible property of a shape one object followed by pointers to get and set handlers for the FontSize property of a shape one object. The FontSize property of ColorButton is accessed, therefore, using the pointers to the second set of get and set handlers in the conversion method vector 282, thereby converting from shape one to shape three. The get and set methods are passed another invisible parameter, a SELF reference, that identifies the ColorButton object and that indicates that the property values of that particular object are being accessed. If an object upon which a method operates has the same shape as the method, the property values are accessed by using method pointer vector 252 instead of a conversion method vector 282. Third Embodiment If the third embodiment for organizing data as described above is used, the steps used to execute a method are similar to those shown in FIG. 19, but there are some differences. When a method is compiled in this embodiment, property names 124 are reduced to property name table index numbers 122, but not to within-object property numbers. Thus neither map table 244 nor conversion method table 356 are required and, therefore, they are not included in shape table 296 (FIG. 17). During method execution, a property such as the FontSize property of the ColorButton object is referred to by its property name table index number. To access the value of the FontSize property of the ColorButton object, the DoubleFontSize method calls a method named FontSize. Because the DoubleFontSize method is operating on the object ColorButton, a SELF reference to ColorButton is included as an invisible parameter with the call to FontSize. The call to FontSize also includes a flag to indicate whether the property value of FontSize is to be set or retrieved. In this embodiment, the behavior 204 for each object includes a method having the name of each property, the method being the access to get or set the property value. A reference to a property of an object is treated as a method call to the object. The method name indicates the property that is to be accessed, and the method call includes a SELF reference to identify the applicable object and a flag indicating whether the value is to be set or retrieved. The method table that comprises the behavior of the object is then searched, and the appropriate method is executed to retrieve or set the property value. As in the second embodiment described above, get and set methods keep track of the exact location and size of the property values. In this embodiment, however, each object has its own get and set methods, rather than each shape having get and set methods. Because the methods are unique for each object, the memory storage of property values within objects of the same shape can be different. Moreover, because the method table is searched to find the get and set methods, as opposed to being indexed, the methods listed in the table do not need to be in any particular order. FIG. 22 is a flow chart illustrating the steps involved in accessing property values during execution of a method. The process begins with step 392 when a property value is requested. Step 400 shows that the property name table index number of the requested property, along with a flag indicating whether the property is to be retrieved or set, is passed to the method table of the object indicated by the SELF invisible parameter of the original method call. Step 402 indicates that the method table is searched to find the method corresponding to the indicated property name table index number and the get or set flag. Step 404 indicates that the appropriate get or set method is executed to return or set the property value. The steps in FIG. 22 show that it is not necessary to access a shape table when performing a simple get or set of a property. A shape table is still required, however, to indicate which shapes can be converted to other shapes. In the first two embodiments for data organization described above, it is desirable for the compiler to convert all references to properties in methods or objects from property name table index numbers 122 (FIG. 8) to within-object property numbers 156 to decrease the time required to access those properties during program execution. When a method is passed a single object, it is possible for the compiler, using the techniques described above, to convert references to property values using property name table index numbers 122 to within-object property numbers 156 of the object acted upon. A SELF reference to the object and to map table 244 or method conversion table 282 was obtained upon entry into the method, so these parameters were available for reducing property names coded in the method to within-object property numbers of the object sent to the method. At times, however, it is necessary to obtain values of properties of objects other than those upon which the method is invoked. In such cases, the compiler will still attempt to reduce property names to within-object property numbers. Because the property value being accessed is not of the SELF object upon which the method is invoked, a pointer to the corresponding conversion means will not be passed with the method call. The compiler will need, therefore, to determine what object that owns the property value being accessed, obtain the shape of the object, and locate the corresponding conversion means in the shape table. The compiler can then use the conversion means to convert the property in the method to a within-object property number for the object that owns the property. In some cases, the shape of the object that owns the property may not be known to the compiler. In such a case, the property name 124 is reduced to its property name table index number 122, but cannot be reduced further to a within-object property number. The property name table index number 122 is then used to reference the property value at run-time, when the shape of the object can be determined. In the first two embodiments for data organization, property list 222 (FIGS. 13, 15 ) is searched to determine the within-object property number, which is used to index into either a property value vector 208 or a method pointer vector 252 to obtain the property value. Separation of Object Description from Object Storage The use of shapes and the techniques of storing property values of the present invention result in a more flexible programming environment than exists in prior art object-oriented languages such as C++, in which the data associated with an object are stored in the order in which the properties are declared or inherited, as shown in FIG. 1. It will be understood that while the structure and content of shape table 134 will vary in different implementations of the invention, some mechanism will be provided to convert from a first shape having a first set of properties to a second shape having a superset of the first set of properties. Moreover, property names will, in each of the embodiments described, be unique within an application and will be ordered by a property name table. Such an arrangement permits methods and objects to refer to properties by an internal index number, i.e., the within-object or within-method property number, thereby improving efficiency and facilitating the implementation of objects and behavior in a system including multiple objects and methods. The rigid memory structure of the prior art necessitates that all properties and methods of a parent be inherited by a child object, which leads to the problems with multiple inheritance described above in the Background of the Invention section. The unique architecture of the present invention allows the actual memory structure of an object to be divorced from the programmer's representation of the object. This separation provides flexibility to a compiler in allocating memory and frees the compiler to perform optimizations that were heretofore impractical. For example, the compiler can share memory structures among different objects, such as a parent and child objects. The separation of structure and representation also allows more flexibility in defining inheritance. Facet.TM.-type Subgroup Inheritance A set of properties within an object can be grouped together and treated as a specific aspect of the object. Such an aspect will be referred to as a Facet.TM.-type property subgroup. A programmer can control by declaration and by object placement which Facet.TM.-type property subgroups of an object are inherited from which parent objects. Parent objects can also be divided into Facet.TM.-type property subgroups from which corresponding Facet.TM.-type property subgroups of child objects are inherited. Inheritance through Facet.TM.-type property subgroups can be implemented in a has-a hierarchy or an is-a hierarchy. In a has-a hierarchy, properties are inherited from corresponding Facet.TM.-type property subgroups of whatever parent containers a child object is placed in. In an is-a hierarchy, properties are inherited from Facet.TM.-type property subgroups of a specified parents. A has-a hierarchy is more suitable to an architecture based on an object prototype model, whereas an is-a inheritance hierarchy is more suited to a class instance model. Through the use of Facet.TM.-type property subgroups, the invention allows a single object to be contained in (has-a) or derived from (is-a) multiple parent objects and allows a programmer to specify by declaration which Facet.TM.-type property subgroups of a child object will be inherited from each of the parent objects, thereby greatly increasing the granularity and flexibility of inheritance. Each Facet.TM.-type property subgroup has one parent, and individual properties within a Facet.TM.-type property subgroup of the child object can be specified as inherited from the parent or not inherited. An object, therefore, can be declared to inherit just the required properties from the relevant parent. In effect, the present invention converts multiple inheritance into multiple single inheritances, thereby eliminating the conflicts inherent in prior art multiple inheritance schemes. Although the description below describes an implementation of Facet.TM.-type property subgroups using a has-a hierarchy, one skilled in the art would be able to implement the invention using an is-a hierarchy in a similar manner. Below is an example of object declarations for objects A through F that appear in a has-a inheritance hierarchy as shown in FIG. 23.
______________________________________
Object A
Facet Font
Property FontSize
Property Control Component
Facet Texture
Property Filled
Property Scroll Component
}
Object B
{
Facet Style
Property Filled
Facet Bkgrnd
Property Color
Property Control Component
Property Scroll Component
}
Object C
{
Facet Font
Property FontSize Inherited
Property Box Component
Facet Bkgrnd
Property Color Inherited
}
Object D
{
Facet Bkgrnd
Property Color Inherited
Facet Texture
Property Filled Inherited
Property Box Component
}
Object E
{
Facet Font
Property FontSize Inherited
Property Caption
Method 1
Facet Appearance
Property Visible
Facet Texture
Property Filled Inherited
Property Bounds
Method 2
}
Object F
}
Facet Font
Property FontSize
Facet Appearance
Property Visible
}
______________________________________
The objects in FIG. 23 are analogous to those of FIG. 3, which describes prior art multiple inheritance. In the present invention, however, it is possible to specify the parent from which properties within a Facet.TM.-type property subgroup are inherited, and it is possible to specify which properties will be inherited and which will not be. In the example of FIG. 3, both objects A and B include a property named Filled. In prior art programming systems, object E ultimately inherited both Filled properties, and it was difficult to determine which, if either, Filled property would be accessed when requesting the Filled property of E. If a method defined in object C depended upon having a specific Filled property from either object A or B, it was uncertain whether the method would work on object E, even though object E had inherited the method from object C. These problems are solved by the present invention. FIG. 23 and the corresponding declarations above show that objects A through F are each divided into Facet.TM.-type property subgroups, each Facet.TM.-type property subgroup being declared as containing specific properties. A property that is itself part of an inheritance hierarchy, such as the Control property of object A, is tagged as a "component" object. When a property is tagged as a component, the object assigned to that property can participate in the inheritance hierarchy, i.e., the assigned object can have properties that inherit values from the parent container. For example, object C may represent a button object. When it is placed in object A, such as by an assignment statement like A.Control=C, the "gateway" opens for the value of properties, such as FontSize, in the Font facet of object A to flow to the same properties in the Font facet of object C. Although the description in object A of the property Control as a component opens the gateway for inheritance, whether or not specific properties are inherited is controlled by declaration in the child object. The tag "inherited" on the FontSize property of object C indicates that the FontSize property value will be inherited from the property of the same name in the corresponding facet of the container parent. Any object having a Font facet could be placed as the Control component in object A. Thus, in a preferred implementation, if a property exists in a facet of the child object, and the child object is placed in a component slot in a parent object facet having the same name as the child object facet and containing the same property, the property in the child object will inherit the value of the property in the parent object, if the property in the child is tagged "inherited." For example, in the declarations above and FIG. 23, object C is contained within both object A and object B. Object C could be, for example, a newsletter story, and objects A and B could be a page and a column of the newsletter or even the newsletter itself. The FontSize property of the Font facet of object C is tagged as inherited. Object C is contained in the Font facet of object A. The FontSize property of object C will therefore be inherited from object A. Object C is also contained in the Bkgrnd facet of object B. The property Color, which is in the Bkgrnd facet of object C and is tagged for inheritance, is, therefore, inherited from object B. Similarly, object D is contained in both objects A and B. Object D inherits its properties Color and Filled from objects B and A, respectively, and passes its property Filled in its Texture facet on to the texture facet of object E. The property Visible in the Appearance facet of object E inherits its value from object F through an is-a inheritance because object F is specified as the parent of the facet Appearance of object E. Thus, inheritance is determined by the explicit declarations of Facet.TM.-type property subgroups in the object definitions, rather than by the order of inheritance and arbitration rules that exist outside of the object. Whether object E inherits property Filled from object C or object D is determined within object E and its immediate parent, not by a set of external rules. A programmer can know that an object E that is placed in an object C will inherit the FontSize property from object C merely by looking at the declarations of objects E and C. Methods of object C, which were dependent upon inheriting the property FontSize from object A and the property Color from object B, will function properly because the inheritance is specified by declaration. Essentially, the invention reduces multiple inheritance to multiple cases of single inheritance, each case being described as a Facet.TM.-type property subgroup. FIGS. 24A and 24B use the seaplane example of FIGS. 1 and 2 to contrast the selective inheritance of the present invention (FIG. 24A) with non-selective, prior art inheritance (FIG. 24B). FIGS. 24A and 24B respectively shows Seaplane object 416 and Seaplane object 418 having parent objects Airplane 10 and Boat 12. FIG. 24A shows that Seaplane object 416 can specify within itself by declaration which Facet.TM.-type property subgroups will be inherited from which of its parent objects. FIG. 24A also shows that if a property, such as landing gear is not required in the child, it is simply not inherited. Thus, although a parent container makes all of its properties available to child objects for inheritance, it is the child object that acts as a "gatekeeper" and determines by its declaration what information from the parent will flow down to the child object. FIG. 24B shows that in the prior art, all properties of the parents are inherited and conflicts between methods are resolved by rules outside of the Seaplane object and related to the order of inheritance. FIG. 24A shows that, in the present invention, the inheritance is controlled within Seaplane object 416. It will be understood that some of the properties of an object will themselves be objects that contain other objects and some of the properties of an object will be simple attributes of the object. In the first embodiment for data organization described above, which uses object memory structure 206 as shown in FIG. 12, property values were stored in a property value vector 208 as part of the object. Properties could be stored either as actual values or as pointers to values. To inherit a property value using this storage technique, object memory structure 206 of the child object contains a pointer to the value stored in object memory structure 206 of the parent object. In such an embodiment, the user of an application can overrule an inherited value by replacing the pointer to the parent object property 208 with an actual value or with a pointer to a new value. FIG. 25 shows an example of inheritance of properties. A Newsletter object 420 has a Font property 422 and a Page property 424. An object Page1 426 includes a Font property 428. A typical object declaration would appear as:
______________________________________
Object Newsletter
{ Facet Typestyle
Property Page Component
Property Font
Object Page1
{ Facet Typestyle
Property Font Inherited
Property Columns
}
______________________________________
The object Page1 is placed in the Page slot of the Newsletter object by an expression such as: Newsletter.Page=Page1 In the declaration of Page1 object 424, its Font property 428 was declared as being inherited from its parent. A property that will be inherited through a has-a hierarchy from a parent container is referred to herein as an "ambient" property because its value is determined by its ambient environment. FIG. 25 shows that the value for Font property 428 in object memory structure 206 (FIG. 12) for Page1 object 424 is a pointer to a Font property 422 entry in object memory structure 206 for Newsletter object 420. In the second embodiment described above, which uses object memory structure 246 shown in FIG. 14, property values are inherited by setting the values in object memory structure 246 to point to the corresponding property in the parent object. When an attempt is made to set the value of a property in a child, the system can let the value be set, thereby removing the link to the parent property value; not allow the property to be set, thereby insisting on the inheritance; or change the value in the parent, thereby allowing the parent to inherit from the child. The first option is typically used, thereby allowing a default value from the parent to be overridden. In the third embodiment, there are no indexed vectors of property values or pointers to get and set handler methods. All values are retrieved or set using methods that are bound at run-time using a method look-up table for each object. The methods used to get an inherited property, therefore, are defined to call the method used in the parent. As in the previous embodiment, the set function can return a NULL value, thereby preventing overriding the inherited value, or the set function can set a value and then modify the get function so that it returns the value, rather than returning the parent value. The inheritance techniques described above provide one-way containment inheritance, that is, the value of the property in the parent becomes the value of the property in the child, but changes in a value in the child do not change the value in the parent. The invention can be implemented to allow changes in a child to flow upward into a parent. The invention can also be implemented so that identity of Facet.TM.-type property subgroups names between the parent and child object are not prerequisites for inheritance. The structure of the Facet.TM.-type property subgroups of each object can be maintained in a symbol table created by the compiler by known techniques. The shape of an object is typically independent of its Facet.TM.-type property subgroup structure. That is, if behavior is defined for the shape (FontSize, Filled), the shape is applicable to Object A above, even though the properties FontSize and Filled are in two different Facet.TM.-type property subgroups of Object A. Thus has been described a novel data structure for an object-oriented architecture that resolves well-known problems in standard object-oriented programming of encapsulation of objects, inheritance order, granularity, and containment hierarchy. In the present invention, inheritance is controlled at the object that is inheriting. A programmer can declare which properties will be inherited from which parent, whether the properties are inherited through an is-a or a has-a hierarchy. The programmer no longer needs to know and analyze the structures of ancestor objects and arbitration rules to determine what an object inherits. The invention, therefore, creates a uniquely extensible, scalable application development architecture and is widely applicable to application designs using objects. The invention corrects the class architecture so that it is unnecessary to rely upon methods of typing or identifying objects using class instance, object prototype, or single containment tree architectures. The invention avoids known methods of resolving the resulting problems using parent class recording, declarative inheritance, custom coding, and overriding, which introduce complexity into the software and do not resolve the underlying problems in the language architecture. The invention modifies the object-oriented language architecture itself to permit the inheritance of methods and properties from multiple containment hierarchies in addition to standard methods using class objects, inheritance, or declaration. This is a significant complement to the historical use of class instance, object prototypes, and single containment trees to define objects. Not only does the use of multiple containment hierarchies resolve the problems of standard object-oriented programming language architectures discussed above, it enables a greatly improved programming architecture with dynamic type identification, inheritance with granularity of a single method or property, and dynamic method inheritance. Standard object-oriented programming uses inheritance and encapsulation to determine whether an object is a member of a set of objects with shared properties. If two objects point to the same parent, they are "made the same." In the present invention, identity is determined only by reference to the properties of the two objects being compared. If two objects share the same set of properties, then they "hold the same set." This invention does not care how the object was made (standard inheritance remains one possible source for object attributes). Methods associated with the object are derived similarly, based solely on the property sets the object contains. Methods are derived independent from the containment hierarchy of the object. This is desirable because objects often cooperate or exist within several environments at the same time and the behavior or properties required depend on the context presented by these environments. For example, a graphic object such as a pie chart may derive properties or behavior from its page (placement, caption size), from its publication type (newsletter or HTML), and from its current output device (printer or display screen). This problem is difficult to solve using a single containment tree, which is the current practice. In the present invention, all classification hierarchies are available to the programmer and no specialized code is required to generate objects with object definition granularized to the level of single properties and methods. The Facet.TM.-type property subgroups architecture declares the organization of an object independent of its methods to permit objects to change dynamically without destroying encapsulation or requiring custom coding. In this way, an application can express how an object's properties can be combined, including ambiguities, without private overriding of methods inherited from a parent class or paternalistic mixing order rules. This architecture makes object-oriented programming the application programmer's domain; the programmer can focus on the application's architecture, rather than demanding expertise in dealing with class libraries. The system of invention can be embodied in an article of manufacture comprising a computer usable storage medium. Such media include magnetic, optical, and silicon articles including diskettes, CD ROMs, and programmable and non-programmable read-only memory. It will be obvious that many changes may be made to the above-described details of the invention without departing from the underlying principles thereof. For example, in the embodiments described above, objects once defined do not go out of scope, i.e., objects defined in one part of a program remain defined throughout the program. It will be understood that the invention could be implemented in a manner such that objects have scope and corresponding entries in the shape table and the property name table are removed when the last object having the particular shape or property goes out of scope. The invention is generally applicable to any software entity or construct that has properties and behavior, and the term "object" as used herein is not to be construed as being limited to any of its various formal definition in different computer languages or models. The breadth of the present invention should, therefore, be determined only by the following claims.
|
Same subclass Same class Consider this |
||||||||||
