Android knowledge points finishing (four)

"Android Advanced Advanced" study notes
the first four articles of new technologies


Chapter 26: Functional programming ideas and their applications in Android

  Functional programming is a programming paradigm, which is based on lambda calculus. Functions of lambda calculus can accept functions as input and output. Compared with imperative programming, functional programming emphasizes that the operation of functions is more important than the execution of instructions, and functions are first-class citizens.

Chapter 27: Dependency Injection and Its Application in Android

1. Basic concepts

  Inversion of control (Inversion of Control, IoC) is one of the important principle of object-oriented programming, programs aimed at reducing the problem of the coupling of the different parts. IoC is generally divided into two types:

  1. Dependency Injection (DI)
  2. Dependency Lookup

Among them, dependency injection is widely used, therefore, general inversion of control and dependency injection can be used interchangeably.

2. An example

Public class Car{
    private Engine mEngine;
    private Wheel mWheel;

    public Car(){
        mEngine = new PetrolEngine();
        mWheel = new MichelinWheel();
    }
}

Disadvantages of the above code:

  • In Car's constructor, you need to create an instance of Engine (same for Wheel).
  • At the same time, you need to find out how to implement Engine. In the above code, Car needs to know the existence of the Engine subclass PetrolEngine.
  • Once you need to change the Engine type from Petrol to Diesel, you also need to modify the Car's constructor.

Solution:

1. Constructor injection:

Public class Car{
    private Engine mEngine;
    private Wheel mWheel;

    public Car(Engine engine, Wheel wheel){
        mEngine = engine;
        mWheel = wheel;
    }
}

2. Setter function injection:

Public class Car{
    private Engine mEngine;
    private Wheel mWheel;

    public Car(){

    }
    public void setEngine(Engine engine){
        mEngine = engine;
    }
    public void setWheel(Wheel wheel){
        mWheel = wheel;
    }
}

3. Interface injection:

//先写一个接口
public interface ICarInject{
    
    
    void bindEngine(Engine engine);
    void bindWheel(Wheel wheel);
}

//Car类实现这个接口
Public class Car implements ICarInject{
    private Engine mEngine;
    private Wheel mWheel;

    public Car(){

    }
    public void bindEngine(Engine engine){
        mEngine = engine;
    }
    public void bindWheel(Wheel wheel){
        mWheel = wheel;
    }
}

Chapter 28: Swift in the Android World: Kotlin's Application in Android

  Kotlin is a JVM-based general programming language similar to Swift, which can be used for server program development, desktop client program development, and Android application development. Using Kotlin, you can easily replace Java in Android projects, or mix with Java.
  Kotlin is an object-oriented programming language that contains many functional programming ideas. It was born to make up for the missing modern language features of the Java language and greatly simplify the code so that developers can write as little boilerplate code as possible.

Chapter 29: React Native For Android Getting Started Guide

  React Native is an open source framework of Facebook. You can use JavaScript to write Android and iOS apps, and the two platforms can consume 70% to 80% of the code.

Chapter 30: Research on Android Online Hot Repair Program

  Can be used for APP updates or emergency bug fixes.

Chapter 31: Aspect-oriented programming and its application in Android

  Aspect Oriented Programming (AOP) is a programming paradigm in software development, a technology that realizes the unified maintenance of program functions through pre-compilation or runtime dynamic agents. It is a continuation of OOP. Developers using AOP can isolate different parts of business logic, thereby further reducing coupling, improving program reusability, and improving development efficiency.

Chapter 32: Transform the Android build system based on Facebook Buck

  Facebook Buck can replace the existing Gradle, used to build the project, generate APK.

Guess you like

Origin blog.csdn.net/michael_f2008/article/details/77943057