SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
UI Design Patterns
Jorge D. Ortiz Fuentes
PoWWaU
Agenda
★Context on design patterns
★MVC
★MVP
★MVVM
★Lessons Learned
2
Intro
★MVVM hotness
★Problems with testability
3
Disclaimer
★Not an expert
★Lack of code here
★Opinionated
4
Some assumptions
★Core Data for persistence
★As few external dependencies
as possible (i.e., no
Reactive Cocoa)
★Examples referred to iOS.
(Many similarities with OS X,
but some differences too)
5
Design Patterns
★Predefined solutions to common
problems with additional benefits:
๏Reusable
๏Loosely coupled
★Some examples:
๏Singleton
๏Delegate
๏Observer
6
Defining a design pattern
1. Name
2. Problem
3. Solution
4. Consequences
7
Painful truth
"Different people reading about MVC in
different places take different ideas from it
and describe these as 'MVC'. If this doesn't
cause enough confusion you then get the
effect of misunderstandings of MVC that
develop through a system of Chinese
whispers.”	

Martin Fowler	

Painful truth
A tricky question
If [Model] + [View] + [Controller
/ Presenter / View Model] =
[TheApp]
How can Controller != Presenter !
= View Model?
★Responsibilities matter!
★Other components (patterns)
might be involved.
10
The goal
★Separation of responsibilities
into roles. Is it? Not
historically. Other motivations.
Solving problem d’jour.
★Now why?
๏Testability
๏Reusability
๏Extensibility
11
Responsibilities
★Handle low level events
★Handle high level events
★Update user interface
★Apply changes to the domain
model
★Presentation logic
★More…
12
MVC: The early days
MVC: The early days
★View
๏Visual representation of the model
๏Receives references to the model to
know the data to display. (Not too
reusable views)
★Controller
๏Deals with user input, app <-> human
(old paradigmas)
๏Shows the widgets change and tell the
model what to do.
★Model
๏Data and business functionality
(domain).
๏No references to the UI.
๏It is observable.
๏Display logic is part of the model.
Ctrlr
ModelView
MVC: The early days
★Separated presentation: Model
<-> Presentation (= V+C)
★Observer originated from MVC,
but observing full object
(properties = scalars)
★Variations: Passive model The
model cannot send updates
(for example HTTP)
15
Apple’s MVC
Apple’s MVC
★View
๏Only UIView subclasses
๏Show information and handle input to generate
higher level events passed to controller
๏Fully reusable views library. Consistent L&F
★Controller
๏Views delegate / control what’s displayed
๏Receive the events and converts them into
calls to the model.
๏_Knows_ about changes in the model and update
what is displayed on the view. Typically a
UIViewController. Responsible of presentation
logic.
★Model
๏Contain the business logic. No references to
the UI.
Flow synchronization vs Observer synchronization
MVC = Composite + Strategy + Observer
Ctrlr
ModelView
MVC Code Distribution
★Model:
๏NSManagedObjectModel,
NSPersistentStore,
NSPersistentCoordinator,
NSManagedObjectContext
๏NSManagedObject
subclasses and its
categories (or additional
methods)
๏UIManagedDocument
๏NSFetchRequests
★Controller:
๏Theme
๏Observer
๏Targets/selectors for the
views actions
๏View delegates
๏Presentation logic
๏NSFetchedResultsControlle
r
★Views:
๏UIButton, UILabel,
UITableView...
Apple’s MVC: testability
★The views are somebody else's (Apple's)
problem.
★Model is easy to test.
★Controller is huge & has dependencies
on the model and on the views. =>
Complex to test.
★Too many levels of abstraction, only a
few methods exposed.
★Some stuff in view controller that it
is usually not tested.
19
MVP
MVP
Origin: IBM & Taligent (=IBM + Apple)
★View
๏Shows information and process the
input gestures transferring control
to the presenter.
๏View is updated using the observer
pattern.
★Presenter
๏Respond to high level events (user
acts)
๏Generates commands (Command
pattern) for the model. (Easy undo
redo)
★Model
๏Receives the commands and acts on
the domain information
Prstr
CmdsInteract
ModelView
Selec
MVP Code Distribution
★Model:
๏NSManagedObjectModel,
NSPersistentStore,
NSPersistentCoordinator,
NSManagedObjectContext, &
UIManagedDocument
๏NSManagedObject subclasses and
its categories (or additional
methods).
๏NSFetchRequests
★Selections:
๏NSFetchedResultsController
★Commands:
๏NSInvocation / NSUndoManager
★Presenter:
๏Observer
๏Targets/selectors for the
views actions & View
delegates.
๏Presentation logic
๏View controller
★Interactors:
๏Gesture recognizers
★Views:
๏UIButton, UILabel…
MVP testability
★Apple's MVC is closer to this than to
classic MVC (Even more compared to the
Dolphin MVP).
★View Controller belongs with the view.
★Properties are now objects, instead of
scalars, so observation is per property.
Easier to deal with indirect invocations.
★More parts, more difficult to write, but
easier to test and reuse.
★If model uses Core Data the command
pattern is almost there (undo/redo).
23
MVVM
MVVM
★View
๏Shows information and process the
input gestures transferring control
to the presenter
๏View is updated using the observer
pattern. View + View Controller
๏Responsible for display logic,
themes...
★View Model
๏Respond to high level events (user
acts) Provides calls to the View
(invoked via the view controller)
๏Validation logic.
★Model
๏Receives the commands and acts on
the domain information
VM
VC
ModelView
MVVM Testability
★The view controller is conceptually attached to the
view role.
★The View Model would be the same for different
platforms, since there isn't any specific mention of
the views.
★Presentation logic (like formatting strings) belongs
to the model. Easier to test exposed methods.
★MVVM is the E&E (embrace and extend) version of MVP.
★Data binding is NOT a key difference.
★Rx programming claim increased testability:
๏doesn't need shared mutable state
๏can be composed
๏no callback hell.
26
MVVM Code Distribution
★Model:
๏NSManagedObjectModel,
NSPersistentStore,
NSPersistentCoordinator,
NSManagedObjectContext, &
UIManagedDocument
๏NSManagedObject subclasses
and its categories (or
additional methods).
๏NSFetchRequests
★View Model:
๏NSFetchedResultsController
๏Observer
๏Targets/selectors for the
views actions & View
delegates.
๏Presentation logic
๏NSInvocation /
NSUndoManager
★Views:
๏UIButton, UILabel…
๏View controller
๏Gesture recognizers
Lessons Learned
Lessons Learned
★Same name used for different
patterns.
★Good to understand patterns
for your business (& mental
health).
★A range of possibilities =
trade offs.
29
References
★Alfonso Alba García
“Bienvenido a la república
independiente de las pruebas
unitarias con Core Data”,
2013

http://es.slideshare.net/
aalbagarcia/bienvenido-a-la-
republica-independiente
★The Gang of 4, “Design
Patterns: Elements of
Reusable Object-Oriented
Software”, 1994
★Derek Greer “Interactive
Application Architecture
Patterns”, 2007

http://aspiringcraftsman.com/
2007/08/25/interactive-
application-architecture/
★Martin Fowler, "Patterns of
Enterprise Application
Architecture”, 2002
★Martin Fowler, “GUI
Architectures”, 2006

http://martinfowler.com/
eaaDev/uiArchs.html
★Ash Furrow “Model-View-
ViewModel for iOS”, 2014

http://www.teehanlax.com/
blog/model-view-viewmodel-
for-ios/
Thank you!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentation
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
Mvvm basics
Mvvm basicsMvvm basics
Mvvm basics
 
Introduction To Model View Presenter
Introduction To Model View PresenterIntroduction To Model View Presenter
Introduction To Model View Presenter
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobile
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Why Use MVC?
Why Use MVC?Why Use MVC?
Why Use MVC?
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 

Similar a Ui design patterns

реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработкеProvectus
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVMBoulos Dib
 
Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernatebwullems
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET WebskillsCaleb Jenkins
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP DevelopersEdureka!
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Jennie Gajjar
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshopJorge Ortiz
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaYi-Shou Chen
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeDr. Syed Hassan Amin
 
Which is better asp.net mvc vs asp.net
Which is better  asp.net mvc vs asp.netWhich is better  asp.net mvc vs asp.net
Which is better asp.net mvc vs asp.netConcetto Labs
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesQamar Abbas
 
Models used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVMModels used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVMAndrei Popa
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture Jiby John
 

Similar a Ui design patterns (20)

реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVM
 
Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernate
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET Webskills
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
 
UI Design Patterns
UI Design PatternsUI Design Patterns
UI Design Patterns
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
 
MVVM and Prism
MVVM and PrismMVVM and Prism
MVVM and Prism
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshop
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Ios models
Ios modelsIos models
Ios models
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoa
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better Code
 
Which is better asp.net mvc vs asp.net
Which is better  asp.net mvc vs asp.netWhich is better  asp.net mvc vs asp.net
Which is better asp.net mvc vs asp.net
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Models used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVMModels used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVM
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
 
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
 

Más de Jorge Ortiz

Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Jorge Ortiz
 
Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Jorge Ortiz
 
Automatización de interfaces e introducción a bdd
Automatización de interfaces e introducción a bddAutomatización de interfaces e introducción a bdd
Automatización de interfaces e introducción a bddJorge Ortiz
 
Multipeer Connectivity Framework
Multipeer Connectivity FrameworkMultipeer Connectivity Framework
Multipeer Connectivity FrameworkJorge Ortiz
 
¿Cuánto cuesta una app?
¿Cuánto cuesta una app?¿Cuánto cuesta una app?
¿Cuánto cuesta una app?Jorge Ortiz
 
Aplicaciones para iphone accesibles
Aplicaciones para iphone accesiblesAplicaciones para iphone accesibles
Aplicaciones para iphone accesiblesJorge Ortiz
 
Introduccion a core plot
Introduccion a core plotIntroduccion a core plot
Introduccion a core plotJorge Ortiz
 

Más de Jorge Ortiz (12)

Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Fiscalidad en el app store 2014
Fiscalidad en el app store 2014
 
Fiscalidad en el app store 2014
Fiscalidad en el app store 2014Fiscalidad en el app store 2014
Fiscalidad en el app store 2014
 
Automatización de interfaces e introducción a bdd
Automatización de interfaces e introducción a bddAutomatización de interfaces e introducción a bdd
Automatización de interfaces e introducción a bdd
 
Multipeer Connectivity Framework
Multipeer Connectivity FrameworkMultipeer Connectivity Framework
Multipeer Connectivity Framework
 
iBeacons
iBeaconsiBeacons
iBeacons
 
Kata tdd
Kata tddKata tdd
Kata tdd
 
Autolayout
AutolayoutAutolayout
Autolayout
 
Crashlitycs
CrashlitycsCrashlitycs
Crashlitycs
 
¿Cuánto cuesta una app?
¿Cuánto cuesta una app?¿Cuánto cuesta una app?
¿Cuánto cuesta una app?
 
Runtime
RuntimeRuntime
Runtime
 
Aplicaciones para iphone accesibles
Aplicaciones para iphone accesiblesAplicaciones para iphone accesibles
Aplicaciones para iphone accesibles
 
Introduccion a core plot
Introduccion a core plotIntroduccion a core plot
Introduccion a core plot
 

Último

Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"DianaGray10
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Alexander Turgeon
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...Daniel Zivkovic
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
IEEE Computer Society’s Strategic Activities and Products including SWEBOK Guide
IEEE Computer Society’s Strategic Activities and Products including SWEBOK GuideIEEE Computer Society’s Strategic Activities and Products including SWEBOK Guide
IEEE Computer Society’s Strategic Activities and Products including SWEBOK GuideHironori Washizaki
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 

Último (20)

Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
IEEE Computer Society’s Strategic Activities and Products including SWEBOK Guide
IEEE Computer Society’s Strategic Activities and Products including SWEBOK GuideIEEE Computer Society’s Strategic Activities and Products including SWEBOK Guide
IEEE Computer Society’s Strategic Activities and Products including SWEBOK Guide
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 

Ui design patterns

  • 1. UI Design Patterns Jorge D. Ortiz Fuentes PoWWaU
  • 2. Agenda ★Context on design patterns ★MVC ★MVP ★MVVM ★Lessons Learned 2
  • 4. Disclaimer ★Not an expert ★Lack of code here ★Opinionated 4
  • 5. Some assumptions ★Core Data for persistence ★As few external dependencies as possible (i.e., no Reactive Cocoa) ★Examples referred to iOS. (Many similarities with OS X, but some differences too) 5
  • 6. Design Patterns ★Predefined solutions to common problems with additional benefits: ๏Reusable ๏Loosely coupled ★Some examples: ๏Singleton ๏Delegate ๏Observer 6
  • 7. Defining a design pattern 1. Name 2. Problem 3. Solution 4. Consequences 7
  • 9. "Different people reading about MVC in different places take different ideas from it and describe these as 'MVC'. If this doesn't cause enough confusion you then get the effect of misunderstandings of MVC that develop through a system of Chinese whispers.” Martin Fowler Painful truth
  • 10. A tricky question If [Model] + [View] + [Controller / Presenter / View Model] = [TheApp] How can Controller != Presenter ! = View Model? ★Responsibilities matter! ★Other components (patterns) might be involved. 10
  • 11. The goal ★Separation of responsibilities into roles. Is it? Not historically. Other motivations. Solving problem d’jour. ★Now why? ๏Testability ๏Reusability ๏Extensibility 11
  • 12. Responsibilities ★Handle low level events ★Handle high level events ★Update user interface ★Apply changes to the domain model ★Presentation logic ★More… 12
  • 14. MVC: The early days ★View ๏Visual representation of the model ๏Receives references to the model to know the data to display. (Not too reusable views) ★Controller ๏Deals with user input, app <-> human (old paradigmas) ๏Shows the widgets change and tell the model what to do. ★Model ๏Data and business functionality (domain). ๏No references to the UI. ๏It is observable. ๏Display logic is part of the model. Ctrlr ModelView
  • 15. MVC: The early days ★Separated presentation: Model <-> Presentation (= V+C) ★Observer originated from MVC, but observing full object (properties = scalars) ★Variations: Passive model The model cannot send updates (for example HTTP) 15
  • 17. Apple’s MVC ★View ๏Only UIView subclasses ๏Show information and handle input to generate higher level events passed to controller ๏Fully reusable views library. Consistent L&F ★Controller ๏Views delegate / control what’s displayed ๏Receive the events and converts them into calls to the model. ๏_Knows_ about changes in the model and update what is displayed on the view. Typically a UIViewController. Responsible of presentation logic. ★Model ๏Contain the business logic. No references to the UI. Flow synchronization vs Observer synchronization MVC = Composite + Strategy + Observer Ctrlr ModelView
  • 18. MVC Code Distribution ★Model: ๏NSManagedObjectModel, NSPersistentStore, NSPersistentCoordinator, NSManagedObjectContext ๏NSManagedObject subclasses and its categories (or additional methods) ๏UIManagedDocument ๏NSFetchRequests ★Controller: ๏Theme ๏Observer ๏Targets/selectors for the views actions ๏View delegates ๏Presentation logic ๏NSFetchedResultsControlle r ★Views: ๏UIButton, UILabel, UITableView...
  • 19. Apple’s MVC: testability ★The views are somebody else's (Apple's) problem. ★Model is easy to test. ★Controller is huge & has dependencies on the model and on the views. => Complex to test. ★Too many levels of abstraction, only a few methods exposed. ★Some stuff in view controller that it is usually not tested. 19
  • 20. MVP
  • 21. MVP Origin: IBM & Taligent (=IBM + Apple) ★View ๏Shows information and process the input gestures transferring control to the presenter. ๏View is updated using the observer pattern. ★Presenter ๏Respond to high level events (user acts) ๏Generates commands (Command pattern) for the model. (Easy undo redo) ★Model ๏Receives the commands and acts on the domain information Prstr CmdsInteract ModelView Selec
  • 22. MVP Code Distribution ★Model: ๏NSManagedObjectModel, NSPersistentStore, NSPersistentCoordinator, NSManagedObjectContext, & UIManagedDocument ๏NSManagedObject subclasses and its categories (or additional methods). ๏NSFetchRequests ★Selections: ๏NSFetchedResultsController ★Commands: ๏NSInvocation / NSUndoManager ★Presenter: ๏Observer ๏Targets/selectors for the views actions & View delegates. ๏Presentation logic ๏View controller ★Interactors: ๏Gesture recognizers ★Views: ๏UIButton, UILabel…
  • 23. MVP testability ★Apple's MVC is closer to this than to classic MVC (Even more compared to the Dolphin MVP). ★View Controller belongs with the view. ★Properties are now objects, instead of scalars, so observation is per property. Easier to deal with indirect invocations. ★More parts, more difficult to write, but easier to test and reuse. ★If model uses Core Data the command pattern is almost there (undo/redo). 23
  • 24. MVVM
  • 25. MVVM ★View ๏Shows information and process the input gestures transferring control to the presenter ๏View is updated using the observer pattern. View + View Controller ๏Responsible for display logic, themes... ★View Model ๏Respond to high level events (user acts) Provides calls to the View (invoked via the view controller) ๏Validation logic. ★Model ๏Receives the commands and acts on the domain information VM VC ModelView
  • 26. MVVM Testability ★The view controller is conceptually attached to the view role. ★The View Model would be the same for different platforms, since there isn't any specific mention of the views. ★Presentation logic (like formatting strings) belongs to the model. Easier to test exposed methods. ★MVVM is the E&E (embrace and extend) version of MVP. ★Data binding is NOT a key difference. ★Rx programming claim increased testability: ๏doesn't need shared mutable state ๏can be composed ๏no callback hell. 26
  • 27. MVVM Code Distribution ★Model: ๏NSManagedObjectModel, NSPersistentStore, NSPersistentCoordinator, NSManagedObjectContext, & UIManagedDocument ๏NSManagedObject subclasses and its categories (or additional methods). ๏NSFetchRequests ★View Model: ๏NSFetchedResultsController ๏Observer ๏Targets/selectors for the views actions & View delegates. ๏Presentation logic ๏NSInvocation / NSUndoManager ★Views: ๏UIButton, UILabel… ๏View controller ๏Gesture recognizers
  • 29. Lessons Learned ★Same name used for different patterns. ★Good to understand patterns for your business (& mental health). ★A range of possibilities = trade offs. 29
  • 30. References ★Alfonso Alba García “Bienvenido a la república independiente de las pruebas unitarias con Core Data”, 2013
 http://es.slideshare.net/ aalbagarcia/bienvenido-a-la- republica-independiente ★The Gang of 4, “Design Patterns: Elements of Reusable Object-Oriented Software”, 1994 ★Derek Greer “Interactive Application Architecture Patterns”, 2007
 http://aspiringcraftsman.com/ 2007/08/25/interactive- application-architecture/ ★Martin Fowler, "Patterns of Enterprise Application Architecture”, 2002 ★Martin Fowler, “GUI Architectures”, 2006
 http://martinfowler.com/ eaaDev/uiArchs.html ★Ash Furrow “Model-View- ViewModel for iOS”, 2014
 http://www.teehanlax.com/ blog/model-view-viewmodel- for-ios/