Mazzy
Mazzy

Reputation: 14179

relation among views and models

In the MVC pattern, if I have two different views, must I have two different models? Is there a one-to-one relationship between the view and the model?

Upvotes: 0

Views: 64

Answers (4)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

MVC (Model View Controller) is a Design Pattern, is based on the principle of Do one thing and do it well...

A Single model can be used with N number of View...thats what the Specialty of MVC.

Model contains the Business Logic and Data

View is what the used to display the result to the user.

Controller is the one on which the action is done

Swing in java is based on MVC. Also know as PLAF (Pluggable Look and Feel).

A Java program where Model is separate from the View, can easily be used with different View.

Eg: A Business Logic well written and separate from the View part, can be used in Swing as well as with JSP to show the Output...

Upvotes: 2

Eduardo Andrade
Eduardo Andrade

Reputation: 966

You can have a single model and different views to present the model.

You may have a model class named User and a view to list the Users, another to insert a new user and another one to update a user.

Cheers!

Upvotes: 0

Pramod Kumar
Pramod Kumar

Reputation: 8014

No it is not mandatory. A model can have one to many relationship with views.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691645

No, of course not. You might use the same model but have a view that displays a resume of the model, another that displays the full details of the model, and a third one which displays it in a form that is well-suited for smart phones.

That's one of the advantages and core principles of the MVC pattern: the controller builds the model, and delegates to the appropriate view to display the model.

Upvotes: 5

Related Questions