Rails apps that decouple ActiveRecord from Business Logic

荒凉一梦 提交于 2019-12-04 14:26:12

问题


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

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

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)


回答1:


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.

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:

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.



来源:https://stackoverflow.com/questions/14194988/rails-apps-that-decouple-activerecord-from-business-logic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!