Git Product home page Git Product logo

android-spi-1's Introduction

SPI

具体场景与使用

在组件化开发中,主工程(app module)会依赖各个子模块(sub module),我们会在主工程中初始化各个子模块, 通常我们的做法是在主工程中分别调用每个子模块初始化类的初始化和反初始化方法,那么问题来了,每增加一个模块就需要添加一行或若干行初始化和反初始化的代码, 当然这样也没什么问题,但是有没有一种更好的方式呢?

又比如在组件化开发中,主工程中的Activity包含若干个Fragment,每个Fragment都代表不同的业务封装在自己的模块中, 如果我们要找到这些Fragment并加载,虽然不是什么难事但是不是不够优雅呢?

那么我们是不是可以在编译时处理这些重复的劳动呢,将各个子模块的初始化类或Fragment类当成一种需要加载的服务,通过注解生成需要调用的代码入口, 在编译时将这些代码插入到统一的注册池中去;每个子模块包括主工程对应的服务实现类(可以叫Service Provider)都继承统一一个抽象类或实现一个接口, 这样我们只需要在主模块中找到那些实现固定抽象类或接口的服务然后统一操作就可以了。

android-spi-1's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.