关注点、装饰者、展示者、服务对象、帮助者——帮助我理解它们 [英] Concerns, Decorators, Presenters, Service Objects, Helpers - Help me Understand Them

查看:35
本文介绍了关注点、装饰者、展示者、服务对象、帮助者——帮助我理解它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 中有一些东西:

There are few things in Rails:

## Concerns
## Decorators
## Presenters 
## Service Objects
## Helpers

谁能给我真正的问题示例,我应该遵循什么类型的情况,以便我更好地了解这些功能.

Can anybody give me real problem example in what type of situation what should I follow, So I can have better understanding of these features.

例子会更好地理解概念

预先感谢并感谢您的关注

Thanks in advance and thanks for looking

推荐答案

嗯,正如我在评论中所说的,你会更好地使用简单的谷歌搜索.

Well, as I said in the comment, you'll be better of with simple google searches.

例如,这是一篇关于其中大部分内容的好文章.

For example, this is a nice article about most of them.

我将向您介绍基础知识.

I'll just walk you through the basics.

  1. 关注点主要是干掉你的模型和控制器.如果您有一个非常胖的控制器/模型,其中包含许多功能(违反 SRP),最好将其分解为几个独立的关注点,然后将它们重新包含在内.这样您还可以在类似的控制器之间共享功能/楷模.这是一篇不错的文章.

装饰器用于将模型的业务逻辑与其用户外观分开.例如.用于存储仅在视图中使用的方法和其他显示.它们还用于扩展对象的逻辑.这里是一篇不错的thoughbot帖子.

Decorators are used for separating models' business logic with their user appearance. E.g. for storing methods only used in the views and for other displaying. They are also used to extend the logic of an object. Here is a nice thoughbot post.

演示者实际上是相同的,但仅用于显示目的.

Presenters are practically the same, but used only for displaying purposes.

服务对象主要用于复杂的逻辑,例如不一定属于特定模型/控制器和/或处理多个模型的复杂逻辑.

Service Objects are mainly used for sophisticated logic that does not necesserally belong in a specific model/controller and/or deals with several models for example.

Helpers 确实用于将逻辑移出视图,从而简化视图模式并干燥视图.通常用于简单的事情(因为否则最好使用装饰器或演示器).

Helpers are solidly for moving logic out of the view and thus simplifying the view patterns and DRYing up the views. Usually used for simple things ('cause otherwise it's better to use a decorator or a presenter).

这篇关于关注点、装饰者、展示者、服务对象、帮助者——帮助我理解它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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