Motivation
I started to think about the relation of DDD and Ruby /Rails when I was thinking about the subject of my final paper for university. First I wanted to write about DDD only, it is subject that doesn’t seem to have much attention among the people that I know. But after reading an Eric Evans (author of the blue book) interview for InfoQ – Domain-Driven Design Quickly book, I realized that DDD + Ruby + Rails was something that I should give a try. For the same reasons I agree with him in the way that Ruby can be a nice platform for doing DDD:
InfoQ: Technology platforms (Java, .NET, Ruby, others) are continually evolving. How does Domain Driven Design fit in?
EVANS: [...] DDD is not specific to a technology platform, but some platforms give more expressive ways of creating business logic, and some platforms have less distracting clutter.
[...] Then you have the new-comers like Ruby. Ruby has a very expressive syntax, and at this basic level it should be a very good language for DDD (although I haven’t heard of much actual use of it in those sorts of applications yet). Rails has generated a lot of excitement because it finally seems to make creation of Web UIs as easy as UIs were back in the early 1990s, before the Web. Right now, this capability has mostly been applied to building some of the vast number of Web applications which don’t have much domain richness behind them, since even these have been painfully difficult in the past. But my hope is that, as the UI implementation part of the problem is reduced, that people will see this as an opportunity to focus more of their attention on the domain. If Ruby usage ever starts going in that direction, I think it could provide an excellent platform for DDD. (A few infrastructure pieces would probably have to be filled in.)
More out on the cutting-edge are the efforts in the area of domain-specific languages (DSLs), which I have long believed could be the next big step for DDD. To date, we still don’t have a tool that really gives us what we need. But people are experimenting more than ever in this area, and that makes me hopeful.
Right now, as far as I can tell, most people attempting to apply DDD are working in Java or .Net, with a few in Smalltalk. So it is the positive trend in the Java world that is having the immediate effect.
So… The book dates from Dec 08, 2006. Has anyone seen a movement toward this direction? I googled about it and I didn’t find anyone talking about a succesful experimentation with the two of them (I’ll add more to that in a minute). Maybe I’m using the wrong keywords or maybe there’s really nothing about. The fact is that there are lots and lots of references and examples of how it works in the context of .NET and Java (and I think some in PHP) but I couldn’t find anything related to Ruby (and Rails).
All that made me come up with the subject for my final paper which will probably be called “Applying Domain-Driven Design with Ruby and Rails” and this blog came as a support for my thoughts.
What (maybe) stop us from doing “DDD on Ruby / Rails”?
After some research I’ve organized a few links about the discussion:
- Discussion on Yahoo Groups
- Domain-driven Ruby on Rails??
- Domain-Driven or Database-Driven?
- Active Record and DDD
They maybe sum up the reasons that people might think we are not able to create an DDD-ish application in Ruby / Rails.
Most of the arguments that I found are that Rails was created for data-centric applications that involves only CRUD. If that is true, it ends up beeing one of the 95% of the applications that won’t benefit from applying DDD. The other main argument probably is that in Rails the domain model entities are implemented using Active Record pattern and that might “break” DDD since it violates the Single Responsibility Principle (and maybe Liskov substition principle as discussed here) and we are bound to the underlaying persistence (which can be considered as a distraction).
But… It is a fact that Rails is a highly productive framework. So, what if we could bring the two worlds together? Instead of not fighting our framework, what if we were able to “quickly” build more complex applications with the combination DDD + Ruby + Rails? It will probably be not so easy but I’m willing to give it a try.
I’ve done some experimentation in that way and I will be posting about it on the next days so that we can discuss it. For now, I can say that I believe that I found a good way to decouple our domain from infrastructure. I’ve managed to model my domain objects as POROs (plain old ruby objects) taking advantage of Ruby’s open classes and modules mixins.
My plan is to make an attempt to rewrite the DDDSample application writen in Java (I’ll just have to check if someone has a problem with that)
Got something to add? Please leave a comment!
Maybe you think I’m crazy to start this discussion or maybe you are pretty sure the we can’t put DDD and Ruby / Rails together, but feel free to drop by and express your opinion. The main purpose of this blog is to concentrate discussion about the topics.



Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago