9
Model View Controller Development architecture

Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

Embed Size (px)

Citation preview

Page 1: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

Model View Controller

Development architecture

Page 2: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC

• Model: the classes encapsulating the functionality of your app

• View: what the user sees and interfaces with

• Controller: middleman between view and model

Page 3: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC

Model does not talk to the View directly

• When the View changes (via an event from the user for example), the Controller can update the Model

• When the Model changes (via some computation, for example), the Controller can refresh the View

Page 4: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Why?

• Separate User Interface and functionality

• Clean design

• Easier to modify your project

• Easier to work as a group or team

• Easier to separate the expertise of people (coding, graphics, ..)

Page 5: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Tic Tac Toe

XX O

O

Page 6: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Tic Tac Toe

• What will be in the View?

• 9 buttons that the user will interact with

• Other things (labels) to tell the user what is going on (anybody won? ) and give some feedback (cannot play here, ..)

Page 7: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Tic Tac Toe

• What will be in the Model?

• i.e. how can we represent the Tic Tac Toe game in a class?

• Natural instance variable = 2-dim array of 3 rows and 3 columns

• Whose turn is it to play?

Page 8: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Tic Tac Toe

• What else will be in the Model?

• i.e. how can we represent playing Tic Tac Toe in a class?

• Functions to play, enforce the rules, update the 2-dim array, determine whose turn is it to play, if the game is over, if somebody won, ..

Page 9: Model View Controller Development architecture. MVC Model: the classes encapsulating the functionality of your app View: what the user sees and interfaces

MVC – Tip calculator

• TipCalculator class

• Instance variables, init method, accessors, mutators, methods to calculate tip, tip per guest, total bill, ..