Analysis of iPhone MVC design patterns

Source: Internet
Author: User

ContactIphoneFrom the knowledge of installation, architecture, and mode to fill in your programming habits, this article describes these.

I. Concepts

The MVC Architecture is a complex architecture, and its implementation is also very complicated. However, we have summarized a lot of reliable design patterns. The combination of multiple design patterns makes the implementation of the MVC Architecture relatively simple. Views can be seen as a tree, which can be implemented by Composite Pattern. The relationship between Views and Models can be reflected by Observer Pattern. The Controller controls the display of Views, which can be implemented using Strategy Pattern. Model is usually a Mediator and can be implemented using Mediator Pattern. Now let's take a look at the position of the three parts of MVC in the J2EE architecture, which helps us understand the implementation of the MVC Architecture. The relationship between MVC and J2EE architecture is: View is in the Web Tier or Client Tier, usually JSP/Servlet, that is, the page display part. The Controller is also in the Web Tier, which is usually implemented using Servlet, that is, the logic part of page display. The Model is in the Middle

2. Communication

1. The Model and View cannot communicate with each other and can only be transmitted through the Controller.

2. The Controller can directly talk to the Model to read and write the call Model). The Model indirectly communicates with the Controller through the Notification and KVO mechanisms.

3. The Controller can directly communicate with the View through outlet to directly operate the View. The outlet directly corresponds to the control in the View ), view reports the occurrence of an event to the Controller through action (for example, user Touch me ).

The Controller is the direct data source of the View. The Controller may have obtained and processed the data from the Model ). Controller is the View proxy delegate) To synchronize the View with the Controller. delegate is a set of protocols, indicating that the View is adjusted when the program is going to or is already in a certain state, to give an explanation to the user. For example, if the system memory is insufficient, do you reduce the view quality to save memory.

Note: A delegate occurs suddenly, which is hard to understand. In fact, it does not correspond to the XXAppDelegate File Created by xcode for us. This file is not part of MVC, although it is related to MVC. I found that when A is the proxy of B in the Apple document, it usually refers to A which has B References and can be directly operated by.

Iii. Implementation

Create a BtnClick project system and generate the following files for us:

 
 
  1. BtnClickAppDelegate.h  
  2. BtnClickAppDelegate.m  

The above two files define the class BtnClicAppDelegate that implements the UIApplicationDelegate protocol. The UIApplicationDelegate protocol is a predefined protocol of the system. It monitors the high-level behavior of applications and processes several key system messages, it is a Hook reserved for the Application lifecycle. Every iphone application is essential. Iphone application lifecycle:

 
 
  1. BtnClickViewController.h  
  2. BtnClickViewController.m 

Implemented Controller in MVC. You can define someIBOutletElement andIBActionMethod to communicate with the View.

 
 
  1. @interface BtnClickViewController : UIViewController{  
  2.     IBOutlet UILabel* statusText;  
  3. }  
  4. @property (retain,nonatomic) UILabel *statusText;  
  5. (IBAction)buttonPressed:(id)sender;  
  6. @end 

What about the file corresponding to the View? The answer is MainWindow. xib and BtnClickViewController. xib under Resource. The MainWindow. xib file is automatically loaded when the application is loaded, which is actually configured in the plist file. MainWindow. xib then loads the subview BtnClickViewController. xib.

Why is it named ViewController instead of separately? It may be because the relationship between View and Controller is too close, and view is the shift of Controller. In actual programming, you must differentiate the responsibilities of each part of MVC. M is optional, especially for simple applications. Any custom class we add that is irrelevant to the interface to define the objects of our application belongs to the category of Model.

Simple introduction to the MVC Framework Design Model of the iPhone

View changes in ASP. net mvc 3

IPhone game development: tools and technologies used

The cool jQuery validation plug-in ASP. NET MVC

Detailed introduction to the new Layout System of ASP. net mvc 3

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.