I was given Practical Object-Oriented Design in Ruby by Sandi Metz for Christmas and it has proven to be a great gift. Actually, Sandi Metz wrote the book, it was my wife who bought me it. I was not able to stop reading it, something my family noted over the Christmas period on more than one occasion. My children have asked how I’m getting on with POODR on a number of occasions. I think they like saying the little nickname for this book. Once I had finished the book, there was only one thing to do and that was start reading it again.
I’m quite careful with buying technical books, because they are pretty expensive for a little hobby on the side. I tend to listen to what others say and read reviews and excerpts before I finally buy a book. I must say I have rarely been disappointed. However this book is one of the best I have ever bought. Having been a little disappointed with Kindle editions of books, I got the paper version and am really pleased with it.
The code examples are very clear and come with syntax highlighting. Sandi makes use of UML where approriate and really walks the reader through design. It feels very genuine, particularly when another refactoring ends up with something that is just OK. She explains why and then has another go to improve it. In my ignorance, I have tended to think for ages about what classes to use, remain undecisive for a long time and finally pick on something that doesn’t feel right. I never knew what it was that was wrong until I read this book.
This book won’t suddenly turn all my coding into world class design, but at least now I have a better idea as to why it isn’t quite right, and thanks to Sandi, I feel a lot more comfortable about what I should change now and what I can change later - when the time is right. The key is to have a design that is easy to change.
I found the first chapter a little difficult to read at first and ended up re-reading some of it. I think I may have been distracted by Christmas related things going on around me. There is always something going on isn’t there? Of course it proved to be a great way to lay the foundation and get me up to speed. By the time Chapter 2 came along I was ready. The book isn’t a massive tome, but it does cover a lot of ground. I am now very clear about many things that were almost empty phrases in the past.
I am now clear about the importance of giving a class a single responsibility, and not treating it like a spare cupboard and shoving everything in it that will kind of fit. I have always tried not to create too many classes in the past, but now I am trying to create classes with just one responsibility. I don’t count how many classes I end up with. Intellectually, I have always known it is important to avoid tightly coupled classes. Sandi provides some examples of how to loosely couple your classes using Ruby, and how to think about it and design loosely coupled classes that could apply to other languages. I’ve learnt about reversing dependency direction, roles, behaviour and the importance of messages.
I am an ocassional lone programmer that does it as a hobby, but not a great deal. I bought Object Oriented Analysis and Design by Grady Booch when it first came out and found myself learning C just so I could understand it. Parts of that book were good and gave me a kind of appreciation of Object Oriented Design. This book from Sandi Metz actually illustrates how to do OOD and do it well. It has been a very satisfying read for me. If you are wanting to get better at design and understand a bit more about Ruby on the way then get this book.