Data interaction between different Java objects (common)

Source: Internet
Author: User

?? Everything in Java is object. Whether you're a thread, an asynchronous task, or ... You can use the following three common methods to interact with data between objects. Of course, Android has its own unique way of interacting with data compared to Java, which is described in a later article, which is intended to summarize the data interactions between common Java objects.

First, passing through the constructor function

?? The constructor is largely a convenient way to pass the parameters, in order to initialize some properties of the object at the time of the new object. We often need to overload the constructor of a class to suit our needs. We can pass the data it needs to the object when it is first built to enable the interaction of data between different objects.

Second, getxxx and Setxxx methods

?? Based on the encapsulation and security considerations in Java object-oriented programming, we often encapsulate the member variables in the class inside the class (that is, using private to decorate them), which improves the security of the data, what if we want to manipulate these member variables? We can use two methods, the first is the public way of the constructor (or constructor), that is, the content of the method, the object of an instantiation of the variable is assigned value. The second approach is through the set and get methods.

?? When we write the Pojo class, we usually set the corresponding get and set methods to the member variables.

?? In fact, the application scenarios of get and set are not limited to this, our thinking can not be limited. In Android, activity wants handler in a child thread, we can write a gethandler method to the child thread, and then call the Gethander method in the activity with the child thread object, we can get the handler of the child thread.

?? Also, the ListView encountered a checkbox, we will build a map in the adapter to store the state of the checkbox, in the activity, in the full selection, cancellation of the button listening method, we need to take the adapter map, and then update the map. The solution is: Write a Getmap method in adapter.

Third, interface callback

?? The previous blog in this section has been described in detail: http://blog.csdn.net/a910626/article/details/45920893

Data interaction between different Java objects (common)

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.