什么是 DCI,它如何与 Rails 兼容? [英] What is DCI and how can it fit with Rails?

查看:15
本文介绍了什么是 DCI,它如何与 Rails 兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近与一位同事关于在 Rails 应用程序中设计和编码模型的不同方法的辩论让我了解到 Rails 上下文中的 DCI.

A recent debate with a co-worker about different approaches to design and code the models in a Rails application brought me across DCI in the context of Rails.

然而,我似乎无法理解整个概念,即使在阅读了这个示例应用程序.

However, I just can't seem to wrap my head around that entire concept, even after going over this example application.

目前,我倾向于或多或少地.

Currently, I tend to just go more or less "by the book" when writing a Rails app.

所以有几件事我想问--

So there are a few things I'd like to ask --

  • 什么是 DCI,当与 MVC 一起实现时,它比普通的旧 MVC(以及 Rails 中的 vanilla ActiveRecord)有什么优势?
  • 它如何在 Rails 中实现(或者换句话说,所有模块都有什么)?

编辑

我想在 RoR 的上下文中进一步扩展我的问题 - 是否推荐在 Rails 中的模型和控制器之间进行另一个抽象级别?它在不同规模的应用中有多普遍?

I'd like to even further expand my question in the context of RoR - is another level of abstraction between the models and the controllers in Rails recommended? How widespread is it in different-scale applications?

推荐答案

DCI 是一种范例,因此不仅仅是一种设计应用程序的方法.这是一种考虑建模和结构化代码的方式.DCI 的重要部分之一是将系统是什么(域模型)和系统做什么(功能)分开.DCI 并不是解决与 MVC 相同问题的不同方法,因此您的第一个问题无法真正得到解答.您可以同时使用 MVC 和 DCI,这并非巧合,因为 Trygve Renskaug 是 MVC 和 DCI 之父.他最近回答了一个/a> 在 google 组object-composition"上.

DCI is a paradigm and hence much more than a way to design an application. It's a way to think about modelling as well as structuring code. One of the important parts of DCI is keeping what the system is (the domain model) and what the system does (functionality) apart. DCI is not a different approach to solving the same problem as MVC so your first question can't really be answered. You can use MVC and DCI simultaneously which is no coincidence since Trygve Renskaug is the father of both MVC and DCI. He recently answered a similar question to this on the google group 'object-composition'.

您链接到的示例违反了一些基本思想,例如将角色对上下文保密,我实际上也找不到单个上下文,但这可能是因为只花了很短的时间浏览代码.

The example you've linked to violates some of the basic ideas such as keeping roles private to the contexts and I couldn't actually find a single context either but that could be due to spending only a short time browsing the code.

我不知道我自己的 RoR,所以我不能给你一个 RoR 的例子,但如果你去fullOO 您会找到用不同语言编写的示例,包括 Ruby 和为 DCI 设计的第一种语言 Marvin.

I don't know RoR my self so I can't give you an RoR example but if you go to fullOO you'll find examples written in different languages including both Ruby and Marvin the first language designed for DCI.

编辑什么是 DCI"这个问题没有简单的答案.DCI 是一种范式,就像 OOP 是一种范式一样.他们都有相同的根源,回答上述问题就像回答什么是面向对象编程"一样复杂.事情变得更加复杂,因为 DCI 是面向对象的,而所有主要 OO 语言中的 OOP 实际上是面向类而不是面向对象的.DCI 旨在生成代码,其中对象在运行时的交互在编译时的代码中是可见的,并且在更一般的术语中试图通过阅读代码更容易地推断运行时的行为.我在上面链接的 站点 专门用于解释 DCI 的全部内容,还列出了一些示例的语言.Ruby 就是其中之一

EDIT There's no simply answer to the question "What is DCI" DCI is a paradigm, just like OOP is a paradigm. They both have the same roots and answering the above question is as complicated as answering "What is object orientented programming". Things are even more complicated by the fact that DCI is object oriented and OOP in all the major OO languages is actually class oriented and not object oriented. DCI aims at producing code where the interaction between objects at run time is visible in the code at compile time and in more general terms tries to mkae it easier to reason about the run time behavior from reading the code. The site I've linked to above is devoted to explaining what DCI is all about and also lists examples in a number of languages. Ruby being one of them

编辑 有一本关于 ruby​​ 和 DCI 的书籍即将出版.作者在对象组合和洞察力方面相当活跃

EDIT There's a book on ruby and DCI on it's way. The author is pretty active on object-composition and insightfull

这篇关于什么是 DCI,它如何与 Rails 兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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