All objects are associated with a unique_name and referenced in the global_object #29
Locked
damskii9992
announced in
ADRs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
General
In EasyScience, we have a unique global object called global_object, whose uniqueness is ensured by deriving from the singleton Borg class. This object has an associated map object based on the Map class, which contains weak references to all objects created in EasyScience. One of the uses of this map, is that any object can be found no matter where it lives and no matter how deeply nested in other objects it is.
Unique_name
Any object from any class inheriting from
BasedBase
orDescriptorBase
(i.e. all objects) has a ' unique_name' string property. Thisunique_name
is by default the class name of the object, subscript a number, such as 'Parameter_1'. The number corresponds to the number of this type of objects that have been created historically at runtime. The iterator for this number is handled by the global_objects_get_name_iterator
method.The user can also set a personal
unique_name
at object creation or afterwards through the objects setter method. Theunique_name
can not be set to aunique_name
which already exists, which is ensured by theglobal_object
'smap
, in theadd_vertex
method, which is the method responsible for adding the reference to themap
, this method raises an error if the usersunique_name
already exists in themap
.The object map
The
unique_name
of objects can be used to get the object, no matter where it lives, using themap
object of theglobal_object
:for this reason, it is advantageous for users to use memorable
unique_name
s for their most important properties.When changing a objects
unique_name
, the oldunique_name
still exists in themap
of theglobal_object
and still references the same object. The newunique_name
is simply added to the weakref dictionary of themap
as en extra reference.To reuse
unique_name
s, which is heavily discouraged due to the risk of existing references getting the wrong object, themap
must first be cleared of the existing entry. This happens naturally due to the weak references when the previous object is deleted and garbage collection is run. As a reminder, garbage collection is normally run automatically, but can be run manually through:If the previous object can not be deleted or garbage collection can not be run, the
maps
entry can also be cleared by using the prune method:Yet this is dangerous and is thus also heavily discouraged.
Link to the ADR suggestion:
#16
Beta Was this translation helpful? Give feedback.
All reactions