Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question