SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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!

Mais conteúdo relacionado

Mais procurados (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?
 

Semelhante 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
 

Semelhante 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
 

Mais 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
 

Mais 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

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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/