Post on 15-Jan-2015
description
Design Pattern
MVC July 17th, 2014
MVC
Agenda
● History ● MVC● Controller specifications● View specifications● Model specifications● Demo
History
Model View Controller (MVC) is one of the most quoted (and most misquoted) patterns around. It started as a framework developed by Trygve Reenskaug for the Smalltalk platform in the late 1970s. Since then it has played an influential role in most UI frameworks and in the thinking about UI design.
MVC● Controller sends commands to the model to update state.
Also sends commands to its associated view to change the appearance.
MVC● Controller sends commands to the model to update state.
Also sends commands to its associated view to change the appearance.
● A model notifies its controllers when there has been a change in its state. This notification allows the views to produce updated output.
MVC● Controller sends commands to the model to update state.
Also sends commands to its associated view to change the appearance.
● A model notifies its controllers when there has been a change in its state. This notification allows the views to produce updated output.
● A view requests information from the model that it needs for generating an output representation to the user.
MVCModel specifications:
● business logic
MVCModel specifications:
● business logic ● has knowledge about itself but does not know
about the controllers and views;
MVCModel specifications:
● business logic ● has knowledge about itself but does not know
about the controllers and views;● in some cases is a database manager or a set
of objects;
MVC Business logic - real-world business rules that determine how data can be created, displayed, stored, and changed.
Model
Model base types:- passive model- active model (basic type)
MVC
Model
ApiClient DataManager
update UI
MVC@property (readonly) DPManagerProvider *provider;
MVC@property (readonly) DPManagerProvider *provider;
#dynamic state
@property (readonly) NSString *email;
@property (readonly) NSString *password;
@property (readonly) NSString *messageText;
@property (readonly) BOOL canEdit;
MVC@property (readonly) DPManagerProvider *provider;
#dynamic state
@property (readonly) NSString *email;
@property (readonly) NSString *password;
@property (readonly) NSString *messageText;
@property (readonly) BOOL canEdit;
#static states@property (readonly) NSString *emailDefaultText;
@property (readonly) NSString *passwordDefaultText;
@property (readonly) NSString *title;
@property (readonly) NSString *loginTitle;
MVC@property (readonly) DPManagerProvider *provider;
#dynamic state
@property (readonly) NSString *email;
@property (readonly) NSString *password;
@property (readonly) NSString *messageText;
@property (readonly) BOOL canEdit;
#static states@property (readonly) NSString *emailDefaultText;
@property (readonly) NSString *passwordDefaultText;
@property (readonly) NSString *title;
@property (readonly) NSString *loginTitle;
#data access methods
- (void)login;
- (BOOL)shouldChangeEmailInRange:(NSRange)range
replacementText:(NSString *)text;
- (BOOL)shouldChangePasswordtInRange:(NSRange)range
replacementText:(NSString *)text;
MVCControllerModel
MVCControllerModel
● Notification
MVCControllerModel
● Notification● KVO
MVCControllerModel
● Notification● KVO● Delegate
MVCControllerModel
● Notification● KVO● Delegate● Binding
MVCController specifications:
● can transmit data
MVCController specifications:
● can transmit data ● can place Views on the screen
MVCController specifications:
● can transmit data ● can place Views on the screen ● can respond to user’s actions
MVCController specifications:
● can transmit data ● can place Views on the screen ● can respond to user’s actions ● can operate with several Views
MVCView specifications:
● can display data
MVCView specifications:
● can display data ● can, in some cases, have code that
implements some business logic
MVC
Controller
Model View
@ view;@ model;
MVC
Controller
Model View
View
MVC
Controller
Model
ViewController
View
MVC
Controller
Model View
View
Controller
MVC
Controller
ModelView
MVC
Controller
ModelView
View
Controller
Model@parameters
MVC
Controller
Model
Storyboard
Controller
Model @parameters
MVCAdditional materials:
● Msdn MVC
● MVC https://developer.apple.com
● Refactoring code
http://martinfowler.com/books/refactoring.html
● Steve McKinley “Perfect Code”
● Eric Freeman “Design Patterns”
Demo: dima.sai github - dsay