Broad design/architecture question. If you have nested components in a GUI, what’s the most common way for those components to interact with data?
For example, let’s say a component receives a click on one of its buttons to save data. Should the save request be delegated up that component’s ancestors, with the uppermost ancestor ultimately passing the request to a controller?
Or are models/datastores in a GUI application typically singletons, so that a component at any level of a hierarchy can directly get/set data?
Or is a controller injected as a dependency down the hierarchy of components, so that any given component is only one intermediary away from the datastore/model?
My first thought is to define a singleton data-layer API, which is callable by GUI components.
If you want multiple instances of the data then give out ‘handles’, which can be stored by GUI components, and passed in to the data layer to get data out again.
This idea is similar to, for example the file system API; or an SQL server API; or any O/S API.