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

本文是小编为大家收集整理的关于Rails上的Ruby模式--装饰者与展示者的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

最近在Ruby的Ruby社区中有各种各样的谈话,涉及 docorators 和演示者.

两者之间的本质区别是什么?如果有的话,什么线索告诉我哪个要比另一个使用?或者也许在连词中使用两个?

推荐答案

装饰器更像是"让我们为该实体添加一些功能".主持人更像是"让我们在模型/后端和视图之间建立桥梁".主持人模式有几种解释.

装饰器是通用/通用.主持人的职责/用途范围更窄.装饰器跨域使用,演示者几乎总是与视图般的功能有关.

其他推荐答案

我建议您检查一下-gah href="http://mikepackdev.com/blog_posts/31-exhibit-vs-presenter" rel="noreferrer">展览vs演讲者.

装饰器是一种设计模式,用于通过包装来扩展特定对象的功能,而无需影响该对象的其他实例.通常,装饰器图案是开放/关闭原则(班级是班级是,班级为关闭以进行修改,但可用于扩展).

展览和演示者图案都是一种装饰器图案.

本文地址:https://www.itbaoku.cn/post/627720.html

问题描述

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.

其他推荐答案

I suggest you to check this - Exhibit vs Presenter.

Decorator is a design pattern that is used to extend the functionality of a specific object by wrapping it, without effecting other instances of that object. In general, the decorator pattern is an example of the open/close principle (the class is closed for modifications, but available for extensions).

Both the exhibit and presenter patterns are a kind of the decorator pattern.