Add a variable to a class instance at runtime: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 166: Line 166:
}</lang>
}</lang>
If the type is variable it can be used an associative array of variants, but things become more complex. Adding a name to all instances of a class can be possible.
If the type is variable it can be used an associative array of variants, but things become more complex. Adding a name to all instances of a class can be possible.

=={{header|Elena}}==
ELENA does not support adding a variable at run-time but it can be simulated with the help of a group object
<lang elena>#subject foo.

#class Object
{
}

#class FieldContainer
{
#field theValue.
#method foo'set : anObject
[
theValue := anObject.
]
#method foo'get = theValue.
}

#symbol Program =>
[
#var anObject := Object.
// adding a field
anObject := #group(anObject, FieldContainer).
anObject set &foo:"bar".
'program'Output << anObject foo.
].
</lang>


=={{header|Falcon}}==
=={{header|Falcon}}==