user interfaces - lecture 16 model - view - controller · 2018. 9. 6. · and nswindowcontroller i...
TRANSCRIPT
![Page 2: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/2.jpg)
Last Lecture Summary
I Default Cocoa application.I NSApplicationI NSApplicationDelegateI XIB/NIB-file storing the visual elementsI RunLoop-event loop class, useful for running timersI Outlet, target and action mechanism.I @IBOutlet-annotationI @IBAction-annotationI Any questions ???
1
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 3: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/3.jpg)
MVC
DefinitionI Introduced in the late 70’s in SmalltalkI Prevalent in many frameworks:
I Web developmentI Cocoa
2
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 4: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/4.jpg)
MVC in ApplicationsGenerally, applications perform the following functions:
3
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 5: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/5.jpg)
MVC in ApplicationsGenerally, applications perform the following functions:
4
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 6: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/6.jpg)
MVC in ApplicationsGenerally, applications perform the following functions:
5
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 7: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/7.jpg)
MVC in Cocoa
I AppKit: classes that provide the view and controllerfunctionality
I Core Data: model that abstracts away details of archiving(In this paper we will be almost always creating our ownmodels)
I Foundation: classes that glue and customise all thecomponents together
6
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 8: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/8.jpg)
MVC in Cocoa ExampleUser interacts with a slider
1. Slider sends a msg to the controller with the new value2. The controller notifies the model about the value change3. The model updates the corresponding value
I Constraints checked, Update, Notification4. Controller notifies the view that the model has changed
7
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 9: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/9.jpg)
AppKitMVC
8
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 10: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/10.jpg)
AppKitMVC
I NSResponder: handling of mouse and keyboard eventsAbstract class
I NSView: rectangle responsible for rendering visualinformation
I Subclass of NSResponderI Abstract class: you either customise by extending it, or use
one of predefined subclasses, such as: NSTabView,NSSplitView, NSScrollView, etc.
I NSControl: sending actions when user interacts with thecontrol
I Don’t confuse with a ControllerI Subclass of NSViewI Abstract class: you either customise by extending it, or use
one of predefined subclasses, such as: NSButton,NSSlider, NSScroller, etc.
9
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 11: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/11.jpg)
AppKitMVC
I Bindings controllers:I NSController, NSObjectController, NSArrayController,
NSUserDefaultsController, and NSTreeControllerI These are special classes that use Cocoa’s bindings and
key value encoding technology, allowing connection andbinding data between view and model elements throughInterface Builder - no code necessary
I These objects implement common logic for mediatingbetween the model and the view
I Application behaviour:I NSDocument, NSDocumentController, NSViewController,
and NSWindowControllerI These control the fundamental aspects of a GUI
application, such as multiple windows, views anddocuments
I Your custom controller: Typically, your application delegate10
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 12: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/12.jpg)
Core DataMVC
I Collection of classes that abstract away the details of howdata is stored and manipulatedYou work with entities (a little bit like a class), attributes(like instance variables in a class), and relationships
I Possible to bind data to controllers in the Interface Builderwithout needing code
I For persistent storage can store data as XML, binaryformat, or in an SQLite database
11
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 13: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/13.jpg)
Summary
I Model-View-Controller pattern underlines the design ofCocoa framework.
I View: code that deals with the visual presentation side ofthe program Tends to change often
I Model: code that implements the underlyingrepresentation that stores the information/content Tends toremain unchanged
I Controller: the code logic that connects the View andModel components
12
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 14: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/14.jpg)
TimerApp
13
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018
![Page 15: User Interfaces - Lecture 16 Model - View - Controller · 2018. 9. 6. · and NSWindowController I These control the fundamental aspects of a GUI application, such as multiple windows,](https://reader035.vdocuments.site/reader035/viewer/2022071009/5fc76d9ef8c9c441e225aa09/html5/thumbnails/15.jpg)
TimerApp MVC
14
Hamza Bennani -*- COSC346 -*- Model - View - Controller -*- September 6, 2018