iOS Development design mode agent

Source: Internet
Author: User

    • Proxy design mode

Proxy design mode, also known as "delegation", as the name implies is entrusted to others to do things

In the proxy mode, one party is called the principal and the other party is called the agent.

The principal and the agent are linked together through the agreement.

When the client wants to get the agent to do something, it only needs to send a proxy message to the agent

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/AC/wKioL1bVqoazWmZsAAD0PUxOfVM247.png "title=" screen shot 2016-03-01 pm 10.40.57.png "width=" 401 "height=" 178 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:401px;height:178px; " alt= "Wkiol1bvqoazwmzsaad0puxofvm247.png"/>


The role of the agent:

1) Passing events between objects: The child told her mother was hungry.

2) Transfer values between objects: Tell Mommy to be hungry and tell her what to eat.

Using Parameters in Proxy methods

3) Assign a value to your own property: The child tells his mother to be hungry and to get her mother's food.

Use return values in Proxy methods


    • Steps to use the proxy design pattern

    1. Principal party: Propose Agency Agreement

@protocol amviewdelegate <NSObject> @optional-(void) View: (amview*) View detailinfowithstate: (BOOL) state; @end

2. Principal: Add proxy object Properties

@interface Amview:uiview@property (nonatomic, weak) id<amappviewdelegate> delegate;

3. Agent: Follow the Agency agreement

@interface Viewcontroller () <AMAppViewDelegate>

4. Agent: Be the agent of the principal party

View.delegate = self;

5. Agent: Implement Proxy method

-(void) View: (amview*) View detailinfowithstate: (BOOL) state{//...}

6. Principal: Invoking proxy methods through proxy properties

-(Ibaction) namebtnclicked: (ID) Sender {if (self.delegate && [self.delegate respondstoselector: @selector (Vie    W:detailinfowithstate:]) {[self.delegate view:self detailinfowithstate:no]; }}


This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1746505

iOS Development design mode agent

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.