iOS Development Guide 8th iOS Common design pattern learning

Source: Internet
Author: User

A design pattern is a solution to a specific problem in a specific scenario

1 single-Case mode

Role: Solve the "only one instance in the application" problem, the role of this instance is global, for example, can realize some of the shared resources method access and State retention

Implementation principle: Typically encapsulates a static property, and provides a way to create a static instance.

***********

James Rumbaugh's definition of a class is that a class is a descriptor for a set of objects that have similar structures, behaviors, and relationships. Class is the most important building block in an object-oriented system. A class diagram shows a set of classes, interfaces, collaborations, and relationships between them.

to create a class diagram:(1) Research and analysis of problem areas to determine system requirements. (2) Determine the class, clarify the meaning and responsibilities of the class, determine properties and operations. (3) determine the relationship between classes. ***********
@synthesize singletondata = _singletondata; initialize static Singleton *sharedmanager =   Nil; + (singleton*) sharedmanager{    static  dispatch_once_t once;  GCD provides a struct that passes the parameter address to the function    dispatch_once (&once, ^{The function is to execute only one block of        code, or thread synchronization = [[Self alloc] init];    });     return Sharedmanager;}
uiapplication class: +shareapplicationidletimerdisabled Properties: Set and get "Idle Time Forbidden"-openurl: Open some built-in iOS apps*-stringbyaddingpercentescapesusingencoding: Converting a string to URL encoding*2 Delegate ModeWe need a class that looks very powerful but is difficult to maintain, assigning his attributes or methods to their classes, or decomposing them into functionally explicit classes, according to their responsibilities. Framework class: Universal reusable features unrelated to the application, keeping a pointer to a delegate object, and sending a message at a specific time like a delegate object. related classes: related to the specific application, due to the Framework class control, the application of related classes are generally designed as "protocol." A delegate object establishes a reference relationship with a generic class: A generic class instance object. Delegate= Delegate Objectfirst three steps: Define the delegate property to hold a reference to the delegate object-establish a delegation agreement. Hnext three steps: declaring implementation delegates-establishing referential relationships-implementing delegate methodsDelegate method Name: the should message should return a Boolean value that determines whether the delegate responds to the messageWill/didthese three methods will send the message object back in the form of parameters3 Observer Patternsan important part of the MVC pattern, also called the Publish/subscribe pattern1) Notification mechanismrecipient: Registration notice-addobserver:selector:name:object:userinfo:Release notification-removeobserver:Delivery object:-postnotificationname:object:userinfo: Dictionary Object-postnotification:It is generally necessary to notify other objects to do something when a program is carried out to a stage2) KVO mechanismsend notifications directly to recipients when object properties change An object that changes the property sends a message asking the observer to start observing the property change: Addobserver:Forkeypath: PropertiesOptions: Settings for property changesnskeyvalueobservingoptions TypeContext: Contextual content is a C language any pointer typeThe Observer needs to rewrite:-observevalueforkeypath:ofobject:change:context: In response to changes in the properties4 MVCUiviewcontroller is the root class of all controllers UIView is the root class for all views and controlsbecause we want to update the views and controls through the controller, we need to define these views as properties of the output typeModel objects can notify the change of data by notification mechanismThe view controller can save a model member variable or property and change the state of the model through them.    

iOS Development Guide 8th iOS Common design pattern learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.