Trusted implementations of Android and iOS

Source: Internet
Author: User

Some time ago wrote a part of iOS program, where the delegation (delegate)/agent is very powerful. Today, we will write a simple commission program for Android and iOS in the principle of delegation to share the following:

1. Project

  

1.1

The first step: Create a new Interface Iproxy (the Protocol (Protocol) in iOS is the same, but there's a difference. It's not much to say)

  

1  Package com.xx; 2 3  Public Interface iproxy {4    string SayHello (string name); 5 }

Step two: New a delegate (proxy class)

1  Packagecom.xx;2 3  Public classAImplementsiproxy{4 5 @Override6      Publicstring SayHello (string name) {7         //TODO auto-generated Method Stub8         return"Hello!" +name;9     }Ten  One}

Step three new Class B

1  Packagecom.xx;2 3  Public classBImplementsiproxy{4 Iproxy proxy;5     6      PublicB (Iproxy proxy) {7         Super();8          This. Proxy =proxy;9     }Ten  One @Override A      Publicstring SayHello (string name) { -         //TODO auto-generated Method Stub -         returnProxy. SayHello (name); the     } -      -}

Fourth Step test (differs from iOS but roughly the same)

1  Packagecom.xx;2 3  Public classTest {4      Public Static voidMain (string[] args) {5A A =NewA ();6         7b b =NewB (a);8System.out.println (B.sayhello ("Xiao Hu")));9     }Ten}

Results:

Hope this article is helpful to everyone, welcome to find the problem and everyone to discuss and solve the problem.

  

Trusted implementations of Android and iOS

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.