2019-10-24 06:02 PM
Hi,
I would like to implement one of the things mentioned in the TouchGFX article 'The Screen Concept and Model-View-Presenter',
https://touchgfx.zendesk.com/hc/en-us/articles/205717801-The-Screen-Concept-and-Model-View-Presenter
namely:
If for instance all your screens need to display a status bar at the top, showing current time, battery level, et cetera you can create a base view class containing the status bar only and have all your views deriving from this class, so you get the status bar functionality automatically.
I understand object oriented programming but I'm confused as to how this would work in practice with touchgfx. For each screen, the designer generates (amongst other things):
- a view class templated on a generated presenter class
- a base view class
- a derived view class
so my hierarchy looks like this:
View<StatusBarPresenter>
^-- StatusBarViewBase
^-- StatusBarView
View<MainPresenter>
^-- MainViewBase
^-- MainView
ie two distinct inheritance hierarchies.
Is the advice above suggesting that I change my MainView to instead inherit from *both* MainViewBase *and* StatusBarViewBase?
When I try this I (understandably) get compilation errors due to multiple inheritance of (non-abstract) classes containing identically named members, in this case eg
error: ‘touchgfx::Screen’ is an ambiguous base of ‘MainView’
So I assume the above multiple inheritance is not what is intended.
If not this, then what?
2019-10-30 04:28 PM
As has been mentioned elsewhere, the solution to this problem seems to be composition rather than inheritance. I used a custom container for the status bar menu and just made sure it is used within each screen, which achieves the desired effect.
I would suggest though, that the documentation page I mentioned is updated/corrected in this regard.