Android体系结构-为什么创建单个实施接口?

时间:2018-12-06 23:06:00

标签: java android kotlin architecture

我从事Android开发已经3年了,我一直想知道为什么要为应用程序架构创建单个实现的接口,就像这样:

interface SomethingRemote {
   fun fetchSomething(): Single<SomethingEntity>
}

然后执行:

class SomethingRemoteImpl(private val service: apiService): SomethingRemote {
   override fun fetchSomething() {
      // Does some logic with the service class to return the specified class defined in the interface
   }
}

我一直关注Google's Sunflower repository,从阅读它到在我的最后几个项目中实现它,实现新功能或进行更改都是遵循Sunflower回购体系结构的轻而易举的事情,但是,我也一直在进行此接口的其他一些项目<-> interfaceImpl东西,还向层中添加了更多的类:

  • 实体
  • ViewModel(不要与Google ViewModel混淆,这只是从模型类映射的UI数据)
  • 远程<-> RemoteImpl
  • 数据源<-> DatsaSourceImpl
  • 存储库<-> RepositoryImpl

所有这些文件和单一实现的接口使添加新功能或更改简单的内容(例如从API修改JSON属性值)成为一项非常令人困惑的任务,同样,我已经看到很多项目在这样做,而我却没有我不明白为什么在与Sunflower所示的体系结构一起使用时,这样的混乱程度较小,而且更“切合实际”,我要求采用这种单一实现的接口方法的好处。

我个人,Im against the "Impl" suffix

0 个答案:

没有答案