Git Product home page Git Product logo

omnipotent's Introduction

Omnipotent

1.前言

  • 开发中,类与类之间交互又以下几种方式: 类之间交互方式.png

  • 上述那么多种方式都具备各种缺点,是否有一种方式能解决上述的大部分缺点呢?

  • Omnipotent 库(万能接口库),它就是解决样式重复代码、类之间交互耦合而诞生,还具备使用简单、链式调用的特点。

  • 本文特点:图片多,字体少

  • 文章中实例 linhaojian的Github


2.目录

目录.png


3.简介

介绍.png


4.原理

4.1 举个例子

  • Activity与Fragment接口交互(Fragment需要把自己的数据发送至Activity) 类与类接口交互.png
  • 上面的例子,在正常使用是没有任何问题,假如遇到以下情况:

1)因业务需求变换/迭代,需要修改接口的函数为无参有返回。 2)新增多个Fragment时,需要创建多个不同接口类。 3)接口函数中参数类型变换或者参数数量增多

  • 这些问题都会让你的代码增加修改成本难度,而且不便于维护、迭代。

4.2 结合Omnipotent

那Omnipotent是如何解决这样的问题呢?我们通过上图例子结合解析如下图: Omnipotent原理.png

  • 从上图可视,Omnipotent充当接口的管理者同时,也是接口函数调用者,触发回调
  • Omnipotent还是类之间交互的桥梁,把它们之间进行解耦

5.使用

5.1 API使用

API.png

5.2 如何在项目使用Omnipotent?

  • 第一步:
 allprojects {
  repositories {
   ...
   maven { url 'https://jitpack.io' }
  }
 }
  • 第二步:
 dependencies {
         implementation 'com.github.linhaojian:Omnipotent:1.2'
 }

5.3 示例

omnipotent.gif


6.设计**

设计**.png


7.总结

  • 到此,Omnipotent库就介绍完毕,希望能在开发过程中帮助大家。
  • 如果喜欢我的分享,可以点击 关注 或者 ,你们支持是我分享的最大动力 。
  • linhaojian的Github

不定期分享关于安卓开发的干货。


写技术文章初心

  • 技术知识积累
  • 技术知识巩固
  • 技术知识分享
  • 技术知识交流

omnipotent's People

Contributors

linhaojian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.