I am programming a bokeh application. I want to split the functionalities into different files. But I want to have some attributes accesible from every class, these attributes should be shared and always updated. For example an attribute which stores a dataframe that all the plots are going to use. So I think I have at least two possible solutions:
Use a big class and include the attributes and methods of other files:
class Bigclass(object): from bk_plots import p1, p2, p3 from bk_data import d1, d2, d3 from bk_layout import ly1, ly2 from bk_events import ev1, ev2 # unfortunately, "from classdefn import *" is an error or warning num = 42 # add more members here if you like
Note: this solution was copied from here (partial classes)
Or I could use inheritance. The parent will have the shared attributes. The perk of this system is that I would need to send the rest of the object references to every subclass
class Parent(): shared = 'parent' class Plot(Parent): def __init__(self): Parent.shared = 'plots' # update class variable from this class # I would need to have references to the objects of other classes class Data(Parent): def __init__(self): Parent.shared = 'second' # [...]
Is there a better way to do this? Which option will bring me less problems?