Skip to content

有了单例池,再也不用在每个单例类里面写 sInstance 了

Notifications You must be signed in to change notification settings

niulinguo/InstancePoolSDK

Repository files navigation

InstancePoolSDK

单例池,再也不用在每个单例类里面写 sInstance 了

相关介绍:单例模式的简化

导入方式

  1. 添加仓库
maven { url 'https://www.jitpack.io' }
  1. 导入 SDK
implementation 'com.github.niulinguo:InstancePoolSDK:v1.1'

使用

  1. 注册单例
InstancePool.register(DbManager.class, new InstanceCreator<DbManager>() {
    @Override
    public DbManager createInstance() {
        return new DbManager();
    }
});
  1. 获取单例
DbManager dbManager = InstancePool.get(DbManager.class);

About

有了单例池,再也不用在每个单例类里面写 sInstance 了

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages