(translated) Getting started--1.3.2 using design Patterns

Source: Internet
Author: User

The design pattern solves a common software engineering problem. The pattern is not coding, it is abstract design. It is used to help developers define the structure of the data model and the interaction of the application. If you adopt a design pattern, you need to adapt its general form to your particular needs. Regardless of the form of your application, it is necessary to understand the basic setup patterns used in the framework. Understanding the settings pattern helps you to use the framework more effectively and helps you write applications that are highly reusable, scalable, and easy to change.

Mvc

Model-View-Controller (MVC) is the core design pattern for iOS app development. MVC sees objects in the application as any of three rules: model, view, controller. In this mode, the model tracks the applied data, the view shows the user's interface and the content of the composition application, and the controller is used to manage the view. The controller is treated as a channel between the model and the view by responding to the user's actions by using the data in the data model to populate the view with the content.

The ToDoList application built in accordance with the previous course also follows the MVC design pattern. The interface you create in storyboard acts as the view layer. Addtodoitemviewcontroller and Todolisttableviewcontrol These two files are the controllers used to manage the views. In the following tutorial, you will merge a data model into your project and work with the view and controller. Before starting the application design, we must take the concept of MVC as the leading thought.

Target-action

Target-action is a simple design pattern at the conceptual level, which is materialized when an object sends a message to another object when a specified event occurs. The action message is actually a selector defined in the source code, the target-the object that receives the message-that is, the object that can perform the action, which is generally performed by the view controller. Objects that send action messages are generally called controls, such as Button,slider,switch, which can trigger events to respond to user interactions such as pressing, dragging, and so on.

Suppose there is a case where you want to store the default settings when the user presses the Restore Defaults button in the app. First, you have to implement an action that executes the logic that stores the default settings. You then need to register the button's touch up inside event to send the action that stores the default settings to the view controller that implements the method.

In the ToDoList application, we have used the target-action mode. When the user presses the Save button in Addtodoitemviewcontroller, the unwindtolist action is triggered. In this case, the Save button is the object that sends the message, the target object is Todolisttableviewcontroller, the action message is: Unwindtolist, the event that receives the message, the triggered action is: the user presses the Save button. Target-action is a powerful mechanism for defining interactions and sending messages between parts of the application.

Agent (delegation)

A proxy is a simple but powerful syntax that, in an application, represents or mates with the behavior of another object. The proxy object holds a reference to another object and, at the appropriate time, the proxy object sends a message to the agent. The agent for the message notification event, which is the event that the proxy object is about to process or has handled. The agent can also respond to messages emitted by its own interface (or status) update, and in some cases it will return a value that affects the processing of upcoming events.

Proxy patterns are ubiquitous in existing frameworks, and you can implement proxies between two custom objects that are applied. A common design pattern for using proxies is that a child view controller can communicate with a parent view controller on a value, especially a value entered by the user.

So far, you're not using proxies, but in later tutorials, you'll use it when you add extra behavior to the Todolisttableviewcontroller class.

These proxy design patterns are just a few of the things you will encounter in iOS development, and of course there are more applications for proxy mode. As Objective-c learns, you'll find more and more proxy patterns that you can use in your app.

(translated) Getting started--1.3.2 using design Patterns

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.