Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adopting "Growing Object-Oriented Software" techniques to Ruby on Rails

I read Growing Object-Oriented Software, Guided by Tests by Steve Freeman and Nat Pryce and was impressed very much. I want to adopt the ideas of this book in my Rails projects using RSpec, though its examples are written in Java.

A basic precept of this book is that we should mock interfaces instead of concrete classes. They say we can improve the application design by extracting interfaces and naming them.

But, Ruby doesn't have any syntax equivalent to Java's interface. How can I utilize their techniques for Rails projects?

UPDATE

For example, in the page 126 the authors introduced Auction interface in order to implement the bid method. Firstly, they mocked Auction.class to make the test pass, then they implemented an Auction class as anonymous inner class in the Main class. Finally, they extracted a new concrete class XMPPAuction from Main (page 131-132).

This incremental approach is the crux of this book in my opinion.

How can I adopt or imitate such a series of code transformation in the Ruby development?

like image 377
Tsutomu Avatar asked Oct 28 '12 02:10

Tsutomu


1 Answers

Check out this previous Stack Overflow answer for a good explanation of interfaces in ruby.

Also, Practical Object-Oriented Design in Ruby is a book in similar vein as Growing Object Oriented Software book, but with ruby examples. Worth checking it out.

like image 155
Prakash Murthy Avatar answered Oct 12 '22 10:10

Prakash Murthy