使ActiveRecord与Business Logic脱钩的Rails应用 [英] Rails apps that decouple ActiveRecord from Business Logic

查看:76
本文介绍了使ActiveRecord与Business Logic脱钩的Rails应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了Robert Martin(鲍勃叔叔)的主题演讲,主题是如何基于用例构建Rails应用程序。我发现这很有趣。

I recently came across Robert Martin's (Uncle Bob) keynote on how to structure a rails app based on use-cases. I found this very interesting.

以下是主题演讲的链接:架构:迷失的年代

Here is the link to the keynote: Architecture: the Lost Years

此处是一个示例项目,该项目根据罗伯特·马丁(Robert Martin)在他的主题演讲:大师手表

Here is a sample project that structures the app based on the principles mentioned by Robert Martin in his keynote: Guru Watch

我想知道如果有成熟的Rails应用程序以这种方式构造(用例驱动方法/实体控制边界架构/后端与前端解耦

I was wondering if there were well established rails applications out there that are structured in such fashion (Use Case Driven Approach / Entity-Control-Boundary architecture / decoupling back end from front-end)

推荐答案

好吧,我不能共享代码,但是可以为您指明方向。我们在应用程序中一直在使用此gem:
https://github.com/collectiveidea/interactor

Well, I can't share the code, but I can point you to some direction. We've been using this gem in our application: https://github.com/collectiveidea/interactor.

我从Martin的主题演讲中得到了很大的启发,并且该应用程序的开发进行得很顺利:)。
在ActiveRecord和业务逻辑分离的情况下,我们执行以下操作:

I was heavily inspired by Martin's keynote, and this app' development went pretty well :). In case of ActiveRecord and Business Logic separation, we did the following:

我们业务逻辑中的每个类都有对应的DatabaseEntity。对方正在使用另一个类-我们的ActiveRecord适配器。它正在查询相应的ActiveRecord模型并将ActiveRecord实例转换为我们的业务逻辑类的实例。

Each class in our business logic had somekind of DatabaseEntity counterpart. This counterpart was using another class - our adapter to ActiveRecord. It was querying corresponding ActiveRecord model and converting ActiveRecord instances to instances of our business logic classes.

毕竟,大多数代码都集中在此适配器中。

After all, most of the code was concentrated in this adapter.

这篇关于使ActiveRecord与Business Logic脱钩的Rails应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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