Introduction-Agent Mode in OC

Source: Internet
Author: User

One , the agent design mode of the occasion:

When object A has some behavior, you want to tell object B (to make object b a proxy object)

Object B wants to listen to some behavior of object A (Make object b a proxy object)

When object A cannot handle certain behaviors, it wants object B to handle it (making object B a proxy object)

Second , the value of the transfer between the objects

To use a proxy: First of all, be clear about who is the agent, who will act as someone else

Please represent the trilogy:

1> write a protocol that lists things that are inconvenient (or do not want to) (@protocol studentdelegate <NSObject>)

2> contains an object that complies with the agreement, and the object can be any type (id<studentdelegate> delegate;)

3> when you have something to tell the agent to do, is to call the agent corresponding method

([Self.delegate studentdidreceivedelivery:self];)

When someone else's acting trilogy:

1> Compliance Agreement (@interface teacher:nsobject<studentdelegate>)

2> implementation of the protocol inside the corresponding method

3> sets the proxy object and assigns a value to the proxy object. Establishing the agency relationship between the two

Introduction-Agent Mode in OC

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.