I
I
i_v2016-04-14 21:29:28
Software design
i_v, 2016-04-14 21:29:28

MVC pattern - How can view get data from a “foreign” model?

Friends, within the same application there are different models and their corresponding views. Suppose normally view A receives data from model A. At the same time, view B displays model B. And suddenly, imagine such a situation, view B has become necessary to depend on the state of model A. How can this be better and more beautiful to implement? Models A and B are separate classes. View'shki subscribed to updates of these models through the event system (observer).
An example is a game in which the player has to complete various tasks. Model A contains all the data about the state of the player - Name, Balance in game currency, Points, List of friends, etc. Some set of views (view A) presents this data on the screen - progress bars of health and money, a list with friends, an avatar, etc. In turn, each job has its own model (models B, C, D, etc.) that encapsulates the business logic of that particular job. View B, C, D display the data of the respective models.
And suddenly view A needed to display data from model B - how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i_v, 2016-04-15
@i_v

Thanks, but if the view is created by external code, and not by the controller itself. How is it technically done? Are multiple models passed during initialization? Doesn't this contradict the idea of ​​mvc?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question