I'm working on client-server application. Client architecture (class hierarchy) looks like this:
System(name is of course different, more descriptive) - represents whole system
Module A- a class instance representing one module. One module = group of similar data and operations
User Module- another module
Users- class instance which represents collection of users, allows adding, removing, reading, etc.
Groups- represents user groups
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
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
User in order to provide
UserView correct data. So, what's the best way for the
UserEventView to access
I can see multiple ways how to solve it, but none seems to be ideal:
Singleton- the most simple and easiest way. Either of
UserEvenViewdoesn't care about it) or for every single module.
Usersinstance is given to
UserEventViewby it's parent, which is provided by it's parent, which is provided by it's parent, ...
- There is
UsersProvidercomponent attached to the
UserViewwhich searches for GUI root where it searches for a component which provides
Systeminstance and obtains
- 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++.
UserEventand (currently) nothing more. I don't know (and don't care) whether this particular
UserEventViewwants 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.