3

I'm currently trying to implement VIPER-architecture in my project, and there is some questions I encountered with.

I have two modules in my app, that have some similar functionality (they both have imagePicker and ability to upload media to server, that implemented absolutely the same for both screens).

My question is how could I reuse this similar functionality in both modules? Trouble is that my imagePicker has many methods declared in Interactor that handle different events while selecting and uploading image (such as didUploadMediaFile(), didFailToUploadMediaFile(), uploadMediaFile() and so on).

Should I create third module with this functionality and then somehow subclass my other modules from it? Or maybe there is a better way of doing it?

4

3 回答 3

1

我将使用的唯一类似的组件/方法是Data Managers,可以在您想要的任意数量的交互器之间共享,并且 100% 符合 VIPER 架构。

因此,一个名为 MediaApiDataManager() 的 DataManager 将负责执行核心代码UploadMediaFile()

我建议您阅读这篇文章以获取有关 VIPER 的更多精彩提示:https ://www.ckl.io/blog/best-practices-viper-architecture/

于 2017-04-11T02:05:51.787 回答
0

我认为您需要创建抽象类并在 imagePicker 逻辑中实现。使用 didUploadMediaFile()、didFailToUploadMediaFile()、uploadMediaFile() 方法为 it 类声明接口(协议),在类中实现此方法并注入您的 VIPER 模块

于 2016-06-06T12:08:14.263 回答
0

对于这两个模块尝试抽象相似之处并尝试构建一个类。如果两个类的数据类型不同,使用泛型,你也可以使用协议,所以在一个协议中声明两个模块的公共方法,并将它们中的每一个作为扩展来实现。也许本教程会有所帮助。https://medium.com/@richiemon/protocol-extension-dispatching-6d5229f1338e

于 2020-07-31T20:14:41.103 回答