Ruby on Rails模式 - 装饰者与演示者 [英] Ruby on Rails patterns - decorator vs presenter

查看:173
本文介绍了Ruby on Rails模式 - 装饰者与演示者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近在Ruby on Rails社区中有关于装饰器和演示者的各种讨论。



两者之间的本质区别是什么?如果有的话,有什么线索告诉我哪一个使用另一个?或者也可以两者结合使用?

解决方案

装饰器更多的是让我们为这个实体添加一些功能。主持人更多的是让我们建立模型/后端与视图之间的桥梁。演示者模式有几种解释。



装饰器是通用/通用的。主持人的责任/用途范围较窄。装饰器跨域使用,演示者几乎总是与观看功能相关。




There is all sorts of talk lately in the Ruby on Rails community about decorators and presenters.

What is the essential difference between the two? If there is, what are the clues that tell me which one to use over the other? Or perhaps to use the two in conjunction?

解决方案

A decorator is more of a "let's add some functionality to this entity". A presenter is more of a "let's build a bridge between the model/backend and view". The presenter pattern has several interpretations.

Decorators are generic/general purpose. Presenters have a narrower range of responsibilities/uses. Decorators are used across domains, presenters are almost always related to view-like functionality.

这篇关于Ruby on Rails模式 - 装饰者与演示者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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