Detailed description of iOS development and design modes

Source: Internet
Author: User

Detailed description of iOS development and design modes

In software development, it is generally considered that there are 23 design patterns, which is a high-level realm in software development. Which design modes are most commonly used in iOS development? Let's analyze it today:

1. [proxy mode]

Application Scenario: when some functions of a class need to be implemented by another class, but you are not sure which class will be implemented. In fact, it is like an interface in Java. classes can implement or do not implement methods in the Protocol (interface.

Advantage: low coupling.

Principle of use: the principle of open and closed.

Instance: TableView's UITableViewDataSource and UITableViewDelegate are used together with protocol to complete proxy.

 

2. [observer mode]

Use Cases: Generally, the model layer is observed, and the Controller and View are notified only to send messages, regardless of who receives them. The status of an object changes, and the notification is sent to the object being observed. These objects respond according to their respective requirements.

Advantage: low coupling.

Usage principle: interface isolation principle and open/closed principle.

Instance: KVO key-value observer. Notification mechanism.

 

Iii. [MVC mode]

Use Case: The entire iOS App system architecture should follow the MVC mode.

Advantage: the layers are clear and easy to maintain.

Instance: The model stores data and displays and responds to views. The controller serves as a bridge between the model and View for logical control.

 

4. [Singleton mode]

Application Scenario: ensure that only one instance is running for resource sharing control.

Advantage: the logic is simple.

Principle: single responsibility.

Instance:

(1) UIAccelerometer class and sharedAccelerometer method. Generally, if the method name contains a word such as shared, it can be considered as an instance variable that can be shared by the entire application. A singleton is generally used.

(2) UIApplication class and sharedApplication method. We generally use this method to create global variables.

(3) NSBundle class and mainBundle method.

(4) NSFileManager class and defaultManager method.

(5) nsicationicationcenter class and defamanager manager method. Nsicationicationcenter also implements the observer mode.

(6) NSUserDefaults class and defaultUser method.

 

V. [policy mode]

Use Cases: define algorithm families and encapsulate them so that they can be replaced with each other.

Advantage: Changes to the algorithm are independent of those who use the algorithm.

Principle: programming for interfaces, rather than implementing programming.

Example: Sorting Algorithm, sortedArrayUsingSelector of NSArray

 

6. [factory model]

Use Case: Create a class instance using the factory method, more than the proxy mode, and create a replaceable proxy class.

Advantages: it is easy to replace and oriented to abstract programming. The application only has a call Relationship with the Common abstract classes of the abstract factory.

Principle: Dependency inversion principle.

Instance: when the project deployment environment depends on multiple different types of databases, you need to use the factory with proxy to replace ease of use.

 

In summary, in actual development, the above models are the most common. If you use other models later, I will continue to share them with you.

 

 

 

Related Article

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.