|
ClassDataStructure
Underlying data structure of objects
Featured IntroductionAn ECT object only stores data about its type and values of its fields. All these data are stored in a record: in each object, the following fields are present:
ExamplesClass animal-class(animal).
?FIELDS({weight, color = red}).The corresponding record definition for this, as generated in animal.class.hrl: -record(animal,{'_types' = {animal},
weight,
color = red}).The result of expression #animal{} is: {animal, {animal}, undefined, red}We can see that weight has the value undefined, because it is not initialized. Class giraffe-class(giraffe).
?SUPERCLASS(animal).
?FIELDS({height = 5, giraffe_id}).The corresponding record definition for this, as generated in giraffe.class.hrl: -record(giraffe,{'_types' = {animal,giraffe},
weight,
color = red,
height = 5,
giraffe_id}).We can see that fields by extension are added at the end of the record. (It is always done this way.) The result of expression #giraffe{} is: {giraffe, {animal, giraffe}, undefined, red, 5, undefined}Field _types is a tuple of the superclasses and class of the object, enumerated in order of inheritance. It makes possible to check an object if it has a particular class, in O(1) time. This type-check is done each time the fields of an object are accessed. |