I'm working on client-server application. Client architecture (class hierarchy) looks like this:
System
(name is of course different, more descriptive) - represents whole systemModule A
- a class instance representing one module. One module = group of similar data and operationsUser Module
- another moduleUsers
- class instance which represents collection of users, allows adding, removing, reading, etc.Groups
- represents user groups
- etc.
Architecture above represents the system, data, operations. Handles client requests and server responses. Caches queries if required. But it does NOT handle GUI, for that I use separated code. The most of the gui uses view for displaying data which is based on simple logic: one view (class) type represents a view of one (single) item type. For example UserView
displays data about user (from User
instance).
Often the item represents a collection of items. For example there might be item like UserEvent
which contains some name (of the event), date and list of users. However, the list of users is implemented as list of IDs (UserId
), nothing more. So now UserEventView
takes this list and wants to create instances of UserView
in order to display more detailed information about users (for example as list of name). So now the UserEventView
needs to access Users
to translate UserId
to User
in order to provide UserView
correct data. So, what's the best way for the UserEventView
to access Users
?
I can see multiple ways how to solve it, but none seems to be ideal:
Singleton
- the most simple and easiest way. Either ofSystem
(even thoughUserEvenView
doesn't care about it) or for every single module.Users
instance is given toUserEventView
by it's parent, which is provided by it's parent, which is provided by it's parent, ...- There is
UsersProvider
component attached to theUserView
which searches for GUI root where it searches for a component which providesSystem
instance and obtainsUsers
from it.
Notes:
- If you want to suggest some exception in design for users, then imagine I'm working with cars, shoes, anything.
- The app is written in C#/C++.
UserEventView
andUserEvent
and (currently) nothing more. I don't know (and don't care) whether this particularUserEventView
wants to display user names or not (and just count, for example). So non-gui code preparing the data a) would need to know whether it's going to be passed to gui which needs the user names or not, or b) always fetch user names even if they're not used.