VIPER - 如果交互器仅返回必要的信息? [英] VIPER - Should the Interactor return only the necessary information?

查看:101
本文介绍了VIPER - 如果交互器仅返回必要的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VIPER 的设计模式,应该交互器返回的所有信息可能是由多个presenter操作中必须使用或我应该为每一个单独的结构?

In the VIPER design pattern, should the Interactor return all the information that might be used by multiple presenter actions or should I have a separate struct for each one?

在我的情况,我有地图显示的地方。为了显示这些地方,我需要检索从PlacesInteractor PlaceItem的名单可能只有一个坐标和颜色(用于改变引脚的头部颜色),将被改造成一个注解由presenter。

In my case, I have a map that displays places. To display those places I need to retrieve a list of PlaceItem's from a PlacesInteractor which could have only a coordinate and a color (used to change the pin's head color) that would be transformed into a annotations by the presenter.

现在可以说,当用户选择地图注解之一,标注泡沫应与更多喜欢的地方的名字,并与颜色的圆圈细节显示出来。

Now lets say that when the user selects one of the annotations in the map, a callout bubble should be displayed with more details like the place's name and a circle with the color.

现在我应该创建一个RetrievePlaceCalloutInteractor,将只返回信息,一个地方,而不是多个地方信息的列表(右?或者我应该只有一个交互器这两种方案?)。

Now I should create a RetrievePlaceCalloutInteractor that would return only the information for one place instead of a list of information for multiple places (Right? Or should I have only one Interactor for both scenarios?).

如果这RetrievePlaceCalloutInteractor返回PlaceCalloutItem仅姓名和地点的颜色(无坐标)或I应该具有坐标,颜色和名称的单个PlaceItem,这将被RetrievePlaceCalloutInteractor并由PlaceInteractor被返回,并将由presenter被用来构造无论是CalloutStruct或MKAnnotations列表?

Should this RetrievePlaceCalloutInteractor return a PlaceCalloutItem with only the name and the color (no coordinate) of the place or should I have a single PlaceItem with coordinate, color and name, that would be returned by the RetrievePlaceCalloutInteractor and by the PlaceInteractor, and would be used by the presenter to construct either a CalloutStruct or a list of MKAnnotations?

感谢您。

推荐答案

VIPER是一个模式,不是很正式的模式,而不是一个宗教或一个完整的应用体系结构。对我来说VIPER帮助更多地思考一个更清洁的架构,但在途中,我不得不作出这样的不关心到很多关于VIPER而是干净的架构是为我的特定方案更好的决策。所以,从我的经验和我的观点回答你的问题是依赖。

VIPER is a pattern, not a very formal pattern, not a religion or a complete app architecture. For me VIPER helped to think more about a cleaner architecture but on the way I had to make decisions that were better for my specific scenario without caring to much about VIPER but about clean architecture. So, from my experience and my point of view the answer to your question is 'depends'.

在我的情况下,大部分的'项目'(我称他们从显示对象或数据对象DO)都与实体(我称他们从MO模型对象)几乎是一对一的关系。大多数交互件操纵一种类型的实体,他们有一个MO-DO映射器。我通常使用相同做不同的使用情况下,如果交互件处理多个用例。

In my case most of the 'Items' (I call them DO from Display Object or Data Object) have almost a one to one relationship with the 'Entities' (I call them MO from Model Object). Most of the interactors manipulate one type of Entity and they have one MO-DO mapper. I usually use the same DO for different use cases if the interactor handle more than one use case.

我也有一些模块中使用不同的DO用于不同用途的情况下,尽管它们涉及到同一实体,而我也有一些民政与结合几个实体的信息,让我们说,例如我所需要的用户名添加它一个博客帖子我用同样的主编DO相结合的发布的和的用户的实体。

I also have some modules using different DOs for different uses cases, although they relate to the same entity, and also I have some DOs with combine the information of several Entities, let's say for example I needed the user name to add it to 'edited by' of a blog post I use the same DO to combine Post and User Entities.

我觉得VIPER想要每个模块有一个交互器,那股力量你有它的多个用例(相关的),但它是由你,如果你想使用不同的项目(我个DO)或只有一个

I think VIPER 'wants' one interactor per module, that kind of forces you to have multiple use cases (related) in it, but it is up to you if you want to use different Items (my DOs) or only one.

作为清洁建筑的纯粹的,你应该有不同的干扰作用,不同的要求和不同的反应为每个用例。

Being a purist of clean architecture you should have different interactors, different requests and different responses for each use case.

所以,我开始,这取决于,重要的是正确地画的界限,如果它是你使用一个或十个项目也没关系。

So, as I started, it depends, the important thing is to 'draw' the boundaries properly and it doesn't matter if it's one or ten Items you use for that.

这篇关于VIPER - 如果交互器仅返回必要的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆