hqt
hqt

Reputation: 30284

MVC Pattern: Does The View should has reference to The Model

In MVC Pattern: when user types something, Control will "translate" user input to Model to process data.

But, in other scene, for example my form has a list box and load data from database when it's loading. So, the loading method I should put in The View or I should call this through Control.

For example: View:

public void Loading(){
   //some init here
   //load data from database
}
public void Loading(){
   //some init here
   //control.loadDatabase();
}

Which is the best in this pattern. Please give me an advice.

Thanks :)

Upvotes: 0

Views: 861

Answers (2)

andrea.marangoni
andrea.marangoni

Reputation: 1499

The list box is part of the view so you should load it with the controller! In mvc the view doesn't t know nothing about model.so you can change the model without changing the view and vice versa.

Upvotes: 0

Daniel Rotter
Daniel Rotter

Reputation: 2056

The relationship between the model and the view is described by a design pattern, called Observer, whereby the model is the subject, and the view an observer. That means that the model notifies the view, when there is new data available.

Upvotes: 3

Related Questions