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.
MVC
Model specifications:
● business logic
MVC
Model specifications:
● business logic
● has knowledge about itself but does not know
about the controllers and views;
MVC
Model 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;
MVC
ControllerModel
MVC
ControllerModel
● Notification
MVC
ControllerModel
● Notification
● KVO
MVC
ControllerModel
● Notification
● KVO
● Delegate
MVC
ControllerModel
● Notification
● KVO
● Delegate
● Binding
MVC
Controller specifications:
● can transmit data
MVC
Controller specifications:
● can transmit data
● can place Views on the screen
MVC
Controller specifications:
● can transmit data
● can place Views on the screen
● can respond to user’s actions
MVC
Controller specifications:
● can transmit data
● can place Views on the screen
● can respond to user’s actions
● can operate with several Views
MVC
View specifications:
● can display data
MVC
View 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
Model
View
MVC
Controller
Model
View
View
Controller
Model
@parameters
MVC
Controller
Model
Storyboard
Controller
Model @
parameters
MVC
Additional 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

Model-View-Controller: Tips&Tricks