Jump to content

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

(+ F#/Omit)
Line 279:
 
=={{header|Elena}}==
ELENA does not support adding a variablefield at run-time but it can be simulated with the help of a group object
<lang elena>#subjectdefine foosystem.
 
#class FieldContainerExtender
{
#field theValuetheObject.
#field theField.
#methodconstructor foo'setnew : anObject
[
theValuetheObject := anObject.
]
#method foo'get = theValuetheField.
#method set &foo : aValue
[
theField := aValue.
]
#method => theObject.
}
 
#symbol Programprogram =
[
#var anObject := 234.
// adding a field
anObject := Extender new:anObject &= FieldContainer.
 
anObject foo'set &foo:"bar".
 
'program'Outputconsole << anObject << ".foo=" << anObject foo.
 
'program'inputconsole getreadChar.
].</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.