Six types of development patterns that are not easily understood in the "dry" iOS development learning

Source: Internet
Author: User

In our actual development, there are more than dozens of architectural patterns, in many models, I believe that many of the first contact with iOS programmers will encounter such problems, the small part of this article for everyone to explain the details of the 6 patterns of application scenarios, to help you clear ideas, learn iOS development.

One, proxy mode application scenario

When some functionality of a class needs to be implemented by another class, it is not certain which class implementation is specific. Advantages: Decoupling Agile Principle: open-closed Principle Example: TableView data source delegate, through and protocol cooperation, complete the request. List row number delegate custom delegate.

As a developer, there is a learning atmosphere with a communication circle is particularly important, this is a My iOS communication group: 638302184, whether you are small white or Daniel Welcome to settle, share bat, a inside test, interview experience, discuss technology, we exchange learning and growth! Hope to help developers less detours.

Second, the Observer Pattern application scenario

Generally for the model layer pair, controller and view of the notification method, do not care who to receive, only responsible for publishing information. Advantages: Decoupling Agile Principle: interface Isolation principle, open-closed Principle example: Notification Notification Center, Registration Notification Center, any location can send messages, registered observer object can be received. KVO, the key value to change the notice of the observer, usually basically useless.

Third, MVC pattern application Scenario

is a very old design pattern, with the data model, controller logic, and view shows that the application is logically partitioned. Advantages: Make the system, level clear, responsibility clear, easy to maintain agile principles: open to Extensions-to modify closed instances: model-is the data model, view-view display, Controller for UI presentation and data interaction logic control.

Four, single-instance mode application scenario

Ensure that the program runs in a class that has only one instance for resource sharing control. Advantage: Easy to use, delay evaluation, easy to cross module Agile principle: Single Responsibility Principle Example: [UIApplication sharedapplication]. Note: Make sure that the user is only available through the GetInstance method, only instances of the Singleton class. Java,c++ it without a public constructor, privatizing and overwriting its constructors. Object C, overriding the Allocwithzone method, ensures that even if the user creates an instance of the Singleton class directly with the Alloc method, only the static variable of this singleton class is returned.

Five, Policy mode application scenario

Define the algorithm families and encapsulate them so that they can be replaced with each other. Advantage: The algorithm's change is independent of the user agile principle using the algorithm: interface isolation principle, multi-use combination, less inheritance, programming for interface, not implementation. Example: Sorting algorithm, Nsarray sortedarrayusingselector; classic Duck will call, can fly case. Precautions:

1, the easy-to-change behavior of the stripping class is embedded in the abstract base class in a combined manner.

2, the behavior of the change abstract base class for, all mutable changes of the parent class.

3, the final instance of the user class, by injecting the behavior instance, sets the variable behavior to prevent the inheritance behavior way, causes the unrelated behavior to pollute the subclass. Policy encapsulation and substitution have been completed.

Six, Factory mode application scenario

Factory mode creates an instance of the class, with more than the proxy pattern, creating a replaceable proxy class. Advantages: Easy to replace, oriented to abstract programming, application only with abstract factory and variable class common abstract class has a call relationship. Agile principle: Dip Dependency Inversion Principle example: when a project deployment environment relies on several different types of databases, use the factory Mate proxy to complete the ease of substitution considerations: This mode is not recommended when the software structure and requirements are not stabilized at the beginning of the project, because the disadvantage is also obvious, Increases the complexity of the code, increases the call level, and increases the memory load. So pay attention to preventing patterns from abusing.

Six types of development patterns that are not easily understood in the "dry" iOS development 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.