Я понимаю, что название ужасное, пожалуйста, не стесняйтесь изменить его или предложить изменения (я новичок в дизайне шаблонов)
У меня есть веб-приложение Dash на основе Python (не совсем актуальное), и я хочу добавить к нему некоторую структуру, однако я не уверен, какой шаблон проектирования использовать.
Структура, которую я пробовал, была:
-- Parent object (initializes all the configuration and instantiates a data object that the rest of the children will need to use)
|
|- Have child objects with methods that return the layout, which I want to be able to call from the parent object
Однако я понял, что это, вероятно, не лучший подход, поскольку сложно вызвать дочерний метод из родительского объекта.
Вот пример:
class Parent:
def __init__(self):
self.data = VaccinationData() <-- created parent so I can use this data in entire project
self.app = dash.Dash()
self.set_layout()
def set_layout(self):
self.app.layout = html.Div(self.child_method()) <-- calling child method
class Child(Parent):
def child_method(self):
# Does some data processing with self.data
return html.Div(
className="right",
children=[self.top_stats(), self.pred_full_vacc()], <-- calling more child's child methods
)
if __name__ == "__main__":
app = Parent()
app.app.run_server(debug=True)
Я новичок в размышлениях о шаблонах проектирования, поэтому буду признателен за любую помощь!