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

查看:21
本文介绍了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?

推荐答案

装饰器更像是让我们向该实体添加一些功能".演示者更像是让我们在模型/后端和视图之间架起一座桥梁".Presenter 模式有多种解释.

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天全站免登陆