Vishwas
Vishwas

Reputation: 1541

Basic programming with MVC

Wanna get views on a very basic structure as follows:

"Person lives inside town ABCTown. ( ABCTown consists of "Person" visually). And "Person" has information about town ABCTown", ie. he has knowledge about his town.

That's all .

A very basic approach would be making two classes Class_Person and Class_ABCTown . And exchanging references of each other.

public class  Class_ABCTown  
{
 var person:Person ; 

 .....
 .....

  public function get personInfo()
  {
     return person.info() ;

  }


 }

public class Person
{

 var  abcTown:ABCTown ; 
   ....
   ....

   public function get townInfo()
  {
    return abcTown.info() ;
   }

}

Now as a programmer, i want to extend the project more towords MVC design pattern. So what do you think, what classes can i add here, and how can i arrange them, to get a MVC design. ( For example Class_ABCTownView can be created to store the reference of PersonView, because visually, person is present inside the town )

Share your views.

Thanks

Upvotes: 0

Views: 156

Answers (2)

tehdoommarine
tehdoommarine

Reputation: 2068

"Person lives inside town ABCTown. ( ABCTown consists of "Person" visually). And "Person" has information about town ABCTown", ie. he has knowledge about his town.

Based off of this I'd create a Person Class, a Town Class and have them consists of a One-Many relationships (one town can have many people). This is all that is needed for the model.

The Controller is sort of like a pointer that directs all user input to the correct action (so if you click the details button the controller will direct the application to go to the view page and display the model).

The view page essentially is used to display information and forms.

If you want an action to happen such as a person moving to a town, you can put in an Edit action for example in the Person Controller to edit information about a person such as which town they live in. This will cause the application to go to an edit view where users can make changes.

This is a well-known tutorial that teaches you what MVC is and how to use it: http://www.asp.net/mvc/tutorials/mvc-music-store

Upvotes: 1

Paul Medcraft
Paul Medcraft

Reputation: 1406

I think you are misunderstanding the MVC pattern. The code above represents the M part of MVC - the data Model. The V (View) would be the classes, JSPs, etc that present the information to the user, and the C (Controller) is the code that handles user interaction, retrieves the data model from persistence, updates the model, binds the model data to the View, etc.

Upvotes: 0

Related Questions