I need advice from experience programmers as I am failing to wrap my head around this. I have the following data structure.
class obj(object):
def __init__(self, data=[], meta=[]):
self.data=data
self.meta=meta
class subobj(object):
def __init__(self, data=[]):
self.data=data
Say, I'm creating the following objects from it.
sub1=subobj([0,1,5])
sub2=subobj([0,1,6])
sub3=subobj([0,1,7])
objA=obj(data=[sub1,sub2], meta=[3,3])
objB=obj(data=[sub3,sub1], meta=[3,3])
Now I am changing sub1 operating on the second object as well as its metadata. For simplicity, I'm writing here via obj. vars without setter/getters:
objB.data[1].data+=[10,11]
objB.meta[1]=5
Now, objA.data[0] has (obviously) changed. But objA.meta[0] stayed the same. I want some func(objB.meta[1]) to be triggered right after the change of the value in objA.data (caused in objB.data) and to change objA.meta as well. Important: this func() uses metadata of the changed sub1 from objB.
I simply don't know how to make every obj know about all other objs that share the same subobj as it does. I could make a func() be triggered upon having that knowledge. I would appreciate any hints.
Notes:
I want to pass those
subobjaround betweenobjs without metadata and let them be changed by those objs. Metadata is supposed to store information that is defined withinobjs, notsubobj. Hence, the value of thefunc()depends on theobjitself, but its definition is the same for allobjs of theclass obj.For simplicity, this
func(metadata)can be something likemultiply3(metadata).I will have thousands of those objects, so I am looking for rather an abstract solution that is not constrained by a small number of objects.
Is that possible in the current design? I am lost as to how to implement this.
data? In your example, you modify the.elsproperty of a subobject.objB.data[1].data+=[10,11].subobjs are simply meant to hold data that is updated by different "parent" objects. But they are objs themselves..dataproperties? Would a tuple instead of a list do? Also, please include@ppperryin your comments when replying to me on your post..dataand want the changes to be propagated to allobjs that hold thesubobj.