Git Product home page Git Product logo

protocolservicekit's Introduction

ProtocolServiceKit

CI Status Version License Platform

东半球最高效的 Protocol<=>Service 中间件,解决中间件的占用内存问题。

OC/Swift 项目均可使用。

业界常用的组件通信方案

URL Router

蘑菇街路线

  • 优点:方案成熟,能解决组件依赖
    • 可多端复用 ✅
  • 缺点:需要注册维护URL表,传递类型单一,编译阶段无法发现潜在BUG 🙅‍♂️
    • 注册存在内存占用问题

Target-Action

  • 优点:不需要注册和内存占用 ✅

  • 缺点:编译阶段无法发现潜在BUG,必须遵守命名规则 🙅‍♂️

Protocol-Class

  • 优点:接口与实现分离,编译阶段就能发现问题 ✅

  • 缺点:需要注册和内存占用

    • repo 简易组件已解决✅

ProtocolServiceKit

  • 优点:同上Protocol-Class 方案,但移除了注册逻辑,解决占用内存问题。
  • 缺点:需要遵从命名规范。(后续更新解决方案doing,参考最下方计划部分)
    • 此缺点可通过维护Plist表做映射关系处理(二次改造)。

建议项目引入搭配方案

  • ProtocolServiceKit 负责组件中间件

  • ZDModuleKit:负责组件生命周期管理

    • 后续更新

Example

To run the example/SwiftExample project, clone the repo, and run pod install from the Example directory first.

  • AccountBusiness <=> PlayBusiness

  组件交互: VIP和播放业务复杂后,只公开Protocol文件决定业务对外能力

    Class <LFLVipProtocol> vipService = ServiceClassWithProtocol(LFLVipProtocol);
    if (vipService && [vipService isCurrentUserVipStatus]) {
        Class <LFLPlayProtocol> playService = ServiceClassWithProtocol(LFLPlayProtocol);
        [playService playMiniVideo];
        
    } else {
        NSLog(@"Error:LFLVipProtocol notfound service Class");
    }

  • 对外业务能力如果未实现,运行期会触发断言处,便于发现问题。

  • recommended convention

    • XXXService

    • XXXProtocol

Installation

ProtocolServiceKit is available through CocoaPods: ProtocolServiceKit. To install it, simply add the following line to your Podfile:

deprecate
pod 'ProtocolServiceManger',"~>1.0.0"

// recommended
pod 'ProtocolServiceKit',"~>1.1.0"

Swift示例

@objc public protocol SwiftTestProtocol {
    
   static func demo()
}

import Foundation

class SwiftTestService:SwiftTestProtocol {
    
  static  public func demo() {
      print("SwiftTestService")
    }
    
}


计划

  • 缓存项目最常用到组件Protocol 和Service 引入白名单 机制
    • 建议为10个以内,KIt内部维护一张表(均存String),用于直接返回ServiceClass
    • 此方案为可选方案。
      • 部分项目存在Service需要为单利场景,建议使用。
  • 引入map机制,可以不按照约定规则来提供Service Class,项目初始化提供map表机制,解决强制命名类规范问题,可自由自定义。

Author

DevdragonLi, [email protected]

License

ProtocolServiceKitis available under the MIT license. See the LICENSE file for more info.

protocolservicekit's People

Contributors

devdragonli avatar

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.