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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
BasedBaseorDescriptorBase(i.e. all objects) has a ' unique_name' string property. Thisunique_nameis 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_iteratormethod.The user can also set a personal
unique_nameat object creation or afterwards through the objects setter method. Theunique_namecan not be set to aunique_namewhich already exists, which is ensured by theglobal_object'smap, in theadd_vertexmethod, which is the method responsible for adding the reference to themap, this method raises an error if the usersunique_namealready exists in themap.The object map
The
unique_nameof objects can be used to get the object, no matter where it lives, using themapobject of theglobal_object:for this reason, it is advantageous for users to use memorable
unique_names for their most important properties.When changing a objects
unique_name, the oldunique_namestill exists in themapof theglobal_objectand still references the same object. The newunique_nameis simply added to the weakref dictionary of themapas en extra reference.To reuse
unique_names, which is heavily discouraged due to the risk of existing references getting the wrong object, themapmust 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
mapsentry 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