ios Design Patterns Jackie Myrose CSCI 5448 Fall 2012



Similar documents
ios App Performance Things to Take Care

How To Develop An App For Ios (Windows)

CS330 Design Patterns - Midterm 1 - Fall 2015

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.

Salesforce Mobile Push Notifications Implementation Guide

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

ios Dev Crib Sheet In the Shadow of C

Object Oriented Programming and the Objective-C Programming Language 1.0. (Retired Document)

Cocoa Fundamentals Guide. (Retired Document)

INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011

When Security Gets in the Way. PenTesting Mobile Apps That Use Certificate Pinning

Design with Reuse. Building software from reusable components. Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 14 Slide 1

MA-WA1920: Enterprise iphone and ipad Programming

JOURNAL OF OBJECT TECHNOLOGY

Architecture. Reda Bendraou

Use Cases. Massimo Felici. Massimo Felici Use Cases c

Advanced Testing and Continuous Integration

Salesforce Mobile Push Notifications Implementation Guide

ios Cloud Development FOR Neal Goldstein WILEY John Wiley & Sons, Inc.

Design Patterns. Design patterns are known solutions for common problems. Design patterns give us a system of names and ideas for common problems.

View Controller Programming Guide for ios

Lecture 2 - Design. 1) Why would you want to make a radical problem normal? We know how to solve normal problems already.

Business-Driven Software Engineering Lecture 3 Foundations of Processes

Designing and Writing a Program DESIGNING, CODING, AND DOCUMENTING. The Design-Code-Debug Cycle. Divide and Conquer! Documentation is Code

Java SE 7 Programming

Adapter, Bridge, and Façade

Development Techniques for Native/Hybrid Tizen Apps. Presented by Kirill Kruchinkin

Contents. About Testing with Xcode 4. Quick Start 7. Testing Basics 23. Writing Test Classes and Methods 28. At a Glance 5 Prerequisites 6 See Also 6

Ch 1: What is Game Programming Really Like? Ch 2: What s in a Game? Quiz #1 Discussion

SPRING INTERVIEW QUESTIONS

Programming Cocoa with Ruby Create Compelling Mac Apps Using RubyCocoa

10 Proxy Pattern [Gamma et al]

ios Development Tutorial Nikhil Yadav CSE 40816/60816: Pervasive Health 09/09/2011

Chapter 1. Introduction to ios Development. Objectives: Touch on the history of ios and the devices that support this operating system.

Unit and Functional Testing for the ios Platform. Christopher M. Judd

File System Programming Guide

Software Engineering. Software Reuse. Based on Software Engineering, 7 th Edition by Ian Sommerville

Client-server 3-tier N-tier

Python Dependency Injection

Aneka Dynamic Provisioning

Building an experimentation framework for web apps - Tutorial Notes

Using the Construct Development Environment to Generate a File-Based Hypermedia Storage Service

Software Development Interactief Centrum voor gerichte Training en Studie Edisonweg 14c, 1821 BN Alkmaar T:

Introduction to Objective-C. Kevin Cathey

Application Programming on the Mac COSC346

In: Proceedings of RECPAD th Portuguese Conference on Pattern Recognition June 27th- 28th, 2002 Aveiro, Portugal

ios App Development for Everyone

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

DATA SYNCHRONIZATION ON MOBILE DEVICES

Software Documentation Guidelines

Pattern-Oriented Architecture for Web Applications

Software Quality Assurance Plan. Introduction

M, N, O F, G, H. network request, 101 ParseFacebookUtilities SDK, 100 profile, 100 user_about_me, 101 -(void)updateindicator, 101

Chapter 1 Fundamentals of Java Programming

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Cloud Computing. Up until now

SwiftScale: Technical Approach Document

Chapter -5 SCALABILITY AND AVAILABILITY


Java EE Web Development Course Program

Symfony2 and Drupal. Why to talk about Symfony2 framework?

XPoints: Extension Interfaces for Multilayered Applications

Rapid Application Development of a Decision Support System using Object Oriented Programming

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

CHOOSING THE RIGHT HTML5 FRAMEWORK To Build Your Mobile Web Application

Assignment 1: Matchismo

How To Write A Composition Engine In A Microsoft Ip System

DEVELOPING AN IOS APPLICATION FOR VALUE STREAM MAPPING WITH SWIFT

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

How To Use Ios 5

iphone SDK Enrolled students will be invited to developer program Login to Program Portal Request a Certificate Download and install the SDK

CURRENT BEST PRACTISES FOR BUILDING ENTERPRISE MOBILE APPLICATIONS

JMS 2.0: Support for Multi-tenancy

Creating & Managing Discussion Forums

Proposal for DSpace Web MVC

DIPLOMADO DE JAVA - OCA

Cucumber: Finishing the Example. CSCI 5828: Foundations of Software Engineering Lecture 23 04/09/2012

Core J2EE Patterns, Frameworks and Micro Architectures

Operating System Organization. Purpose of an OS

Stock Trader System. Architecture Description

Introduction to LabVIEW Design Patterns

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad Spring 2013

Software Development: The Waterfall Model

Commercial software development with the help of J2EE architecture and MVC

A First Set of Design Patterns for Algorithm Animation

Point-of-Sale Developer Guide

A MODEL OF HETEROGENEOUS DISTRIBUTED SYSTEM FOR FOREIGN EXCHANGE PORTFOLIO ANALYSIS

Connect for iphone. Aug, 2012 Ver 5.3b AWest. 1 P age

Business Modeling with UML

Agile Development with Jazz and Rational Team Concert

Java SE 7 Programming

Object-Oriented Design Guidelines

Java SE 7 Programming

Android Developer Fundamental 1

Agile Software Development

Seminar in Software and Service Engineering: Software Ecosystems and Infrastructures Lecture 1: Background to the topic area

Design Patterns. Advanced Software Paradigms (A. Bellaachia) 1

Transcription:

ios Design Patterns Jackie Myrose CSCI 5448 Fall 2012

Design Patterns A design pattern is a common solution to a software problem They are helpful for speeding up problem solving, ensuring that a developer doesn t have to re-invent the wheel for every situation They also give developers a common vocabulary with which to get across high-level ideas with minimal explanation and full understanding

Why ios? Design patterns are everywhere in ios Because ios is a fairly specific platform, developers often face similar problems over and over, so there are a few design patterns that are extremely common in ios

In this presentation Singleton Delegate Model View Controller Observer Façade Command Template Method

Singleton The singleton pattern is very simple but extremely powerful It is a very common pattern, but developers have to be careful not to overuse it Because abuse of the singleton pattern is common, some developers avoid the pattern altogether

Singleton When a class is restricted to just one instantiation, that one object is called a singleton In some situations it can be problematic to have two instances of a class running, this should be the only reason to use the singleton pattern The next slide contains a basic example of creating a singleton in objective-c, however keep in mind that this code is not thread safe

Singleton - code +(ExClass *) singleton{! " "static ExClass *sharedinstance = nil;! " "! " "if ( sharedinstance == nil){! " " "sharedinstance = [[ExClass alloc] init];! " "}! }! " "return sharedinstance;!

Delegate The delegate pattern is another simple, yet powerful design pattern As the name indicates, the delegation pattern is used to have one object delegate control to another object to act on its behalf This is used to keep implementation specific behavior out of the generic class

Delegate Image from: https://developer.apple.com/library/mac/#documentation/cocoa/ conceptual/cocoafundamentals/cocoadesignpatterns/cocoadesignpatterns.html

Delegate Many UI elements in ios use delegates to control their behavior One example of this is UIScrollView The UIScrollView class has no knowledge of what it should be scrolling as that is an application specific task So to notify the application of scrolling events, UIScrollView uses the UIScrollViewDelegate The application can implement the delegate and then intercept the scrolling events sent to it by the UIScrollView The next slide has examples of methods the UIScrollViewDelegate could implement

Delegate - code UIScrollViewDelegate! - scrollviewdidscroll:! - scrollviewwillbegindragging:! - scrollviewwillbegindecelerating:! - scrollviewdidenddecelerating:! - scrollviewdidzoom:

Model View Controller All ios apps use Model View Controllers (MVCs) MVCs are the link between an app s data and its UI The MVC is broken up as such: Model Underlying data View The view the user sees, the UI Controller Determines the interactions between the model and views This keeps the program modularized, allowing for high cohesion and loose coupling

Model View Controller Image from: http://developer.apple.com/library/ios/#documentation/general/ conceptual/devpedia-cocoacore/mvc.html

Observer The observer pattern is used when one object wants to know when another object changes This pattern is build into every NSObject vi Key-Value Observing This is also often used with MVCs because when a model changes you often will want to update the views

Observer Image from: http://www.dofactory.com/patterns/patternobserver.aspx

Observer The observer pattern is similar to the delegate pattern, however one key difference is that observable objects support multiple observers, while a delegate is just one object However, with this expanded possibility comes one big pitfall: you must remember to remove an object as an observer when that object is deallocated, otherwise there will be a code leak The following slide contains a code sample of what the Observable class looks like

Observer - code @interface Observable: NSObject! - (void)addobserver: (id<nsobject>)observer;! - (void)removeobserver: (id<nsobject>)observer;! - (void)notifyobservers: (NSInvocation*)invocation;! @end

Façade The façade pattern is used for simplifying a complex system It allows for a subsystem to be accessed through one entry point, allowing the systems using it to be unaware of the classes in the subsystem This is also useful if the classes under the façade are likely to change, as we can still have the façade class have the same API

Façade One example of this in ios is the NSImage class This class is a façade which provides an interface for using and loading images that can be vector-based or bitmap-based So no matter what type of image the application is using, it can use NSImage and have no knowledge of what s happening underneath the class

Façade Image from: http://www.tutebox.com/2066/computers/ programming/design-patterns-facade-pattern/

Command The command pattern is used for request encapsulation It allows for the separation of an object sending a message from the objects receiving the message The encapsulated request/message is then much more flexible and can be passed between objects, stored for later, dynamically modified, or placed on a queue

Command In ios an example class that is used to encapsulate messages is NSInvocation These objects are used for undo management They contain a target, selector, arguments, and the return value These elements can be set directly and the return value is set automatically when the object is dispatched

Command Image from: http://developer.apple.com/library/ios/#documentation/cocoa/ Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html

Template Method The Template Method design pattern defines the skeleton of an algorithm, leaving some parts to be implemented by subclasses This allows subclasses to refine certain parts of the algorithm without changing the structure In ios this lets parts of a program hook into an algorithm, but the framework still determines how they are needed

Template Method One example of this in ios is the document architecture defined by AppKit, a framework Three classes are key to this architecture: NSDocument, NSWindowController, and NSDocumentController AppKit sends messages to each of these objects at runtime and then requests it to perform specific operations The developer needs to override many methods in these messages to add behavior specific to their application

Template Method Image from: http://java.dzone.com/articles/design-patterns-template-method

Further Resources https://developer.apple.com/library/mac/ #documentation/cocoa/conceptual/cocoafundamentals/ CocoaDesignPatterns/CocoaDesignPatterns.html http://www.amazon.com/pro-objective-c-design- Patterns-iOS/dp/1430233303