Android advanced learning and IOC

Source: Internet
Author: User

1. To become an android player is generally divided into six phases:

Stage 1: proficient in Java SE, especially for its internal classes, threads, concurrency, and network programming, which requires in-depth research; proficient in HTTP-based programming, the process and details of post and get requests are clear; Basic Java Web programming can be performed, which is better if Java EE can be used;

Stage 2: proficient in the use of Android core APIs, such as the APIs and context involved in the four major components, and proficient in the programming of core interfaces, such as listview; at this stage, most basic application development can be done;

Stage 3: proficient in the principles of the application framework, especially the understanding of IOC and Its Application in the Android Application Framework, and proficient in the application of 23 basic design modes in Android;

Stage 4: proficient in JNI, proficient in C/C ++ component development in the android class library, and be able to use the JNI mechanism to port the existing C/C ++ component into the core component of the application framework; ability to modify and compile your own application framework;

Stage 5: Make your own Android system, both at the underlying layer and at the upper layer. You can design and implement a relatively large Android system based on your actual needs, for example, lead a large team to make their own Android mobile products;

Stage 6: potential. All thinking goes into the "trend" thinking. Everything is a matter of thinking. It judges and predicts the situation of Android, leads the market, and leads to a paradise of freedom.

2. IOC for Android (inversion of control)

1) Concept

A design concept. Decouples and separates callers and callers to facilitate changes andCodeReuse to facilitate transplantation.

Many applications use multiple classes to implement business logic through mutual cooperation. Each object is dependent on each other, which leads to high code coupling, difficulty in testing, difficulty in modifying, and difficulty in reusing.

IOC solves this problem, and it will implement the relationship between components fromProgramExternal containers are mentioned internally for management. That is to say, the container dynamically injects a dependency between components into the component at runtime. The relationship between control programs is implemented by external containers.

2) Cases

In order to achieve the decoupling and separation of callers and callers, this is generally achieved through the factory mode. Next we will compare the factory mode and IOC mode to better understand the IOC mode.

Assume that there are two types of B and C: B as callers, and C is called. The general practice is:

 
Public ClassB {
PrivateC comp =NewC ();
......
}

The factory mode is implemented as follows:

Public ClassB {
PrivateC comp;
Private Final StaticMyfactory = myfactory. getinstance ();

PublicB (){
This. Comp = myfactory. createinstanceofc ();

}
Public VoidSomemethod (){
This. Comp. sayhello ();
}
}

Use IOC-dependent injection to implement picocontainer as follows:

  Public   class  B {
private C comp;
Public B (C comp) {
This . comp = comp;
}< br> Public void somemethod () {
This . comp. sayhello ();
}< BR >}
  //   external container implementation, controls the relationship between programs. The cimp class is a specific implementation of the C interface/class.   

Public class client {
Public static void main (string [] ARGs) {
defaultpicocontainer Container = New defaultpicocontainer ();
container. registercomponentimplementation (cimp. class ); /// Class C implementation injection to Class B
container. registercomponentimplementation (B. class );
B = (B) container. getcomponentinstance (B. class );
B. somemethod ();
}< BR >}

3) features and differences between the factory model and IOC:

As shown above, the main difference lies in Class B code. If IOC is used, Class B code does not need to be embedded in any factory code, because these factory models are indirectly related to C, IOC is used to completely decouple the relationship between B and C.

The cost of using IOC is that it is necessary to assemble the relationship between B and C on the client or somewhere else.

Therefore, IOC does not eliminate the relationship between B and C, but only transfers the relationship.
In short, the IOC mode can be used to describe the technical architecture at an abstract level regardless of future implementation.

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.