7: The callback mechanism of Android

Source: Internet
Author: User

Tag: The his full log int instance string will modify the component

1: A simple example

 Public Interface A {    void  printclassname ();}
 Public class Implements A {    publicvoid  printclassname () {        System.out.println ("This is Class b! " );    }}
 Public Static void Main (string[] args) {        new  B ();        A.printclassname ();}

Normal output "This is class B"

Interface A is defined in the main function, and the method of interface A is called, but it is important to note that when instantiated, the new is a concrete class that implements the A interface, and when we call the Printclassname method in A, Java goes back to the method in B. What are the advantages of doing this? Is that when we call, we can completely regardless of the subclass of A is how to implement the method in a, only need to call this method, how to implement, we do not care, that is a subclass of things, this is actually a good way to decouple, if we want to modify the other class, just need to change the subclass after new to the good.

2:

What is the use of this mechanism after we know it? In general, the use of more, is the communication and MVP mode

Communication, in fact, is the communication between different components, can be fragment and activity, can also be adapter and activity;

The above we talked about MVP, this model is really important, for the larger project, the significance is far-reaching, can help us to decouple the overwhelmed activity, but also to facilitate our maintenance and expansion;

7: The callback mechanism of Android

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.