r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
410 stars 56 forks source link

Include reference to Class in Instances #225

Closed iqis closed 3 years ago

iqis commented 3 years ago

If an instance could contain a reference to its class(generator), it would allow methods or outside program to create new objects in the same class.

It could be included as a field class, or more discreetly, as an attribute of the object.

wch commented 3 years ago

It's intentional that the instances don't contain a reference to the generator object; this makes it possible for them to be serialized (saved) without having to save the generator object as well. You could simply add a class field and populate it either in the initialize() method, or with $set(), as in:

MyClass$set("public", "class", MyClass)