From: Phlip Date: 2009-03-08T16:33:21+09:00 Subject: Re: OO style tutorials? Paul Archer wrote: > I'm pretty new to Ruby, and while I've read (and mostly get) several books > on Ruby, I'm having trouble with one thing: Object Oriented programming. > Don't get me wrong, I get the concepts of OO. I can construct objects and > classes. The mechanics of it don't phase me. That is "object based" programming. OO is about virtual dispatch of methods at object boundaries. > I'm good with the how, I'm just a little fuzzy on the how much. To put it > in more concrete terms: I'm writing (or, rather, I want to write) a script > that takes incoming digital images from my camera and renames them and > puts them in a directory structure based on their date. Now, I have a > background in scripting (Bourne shell and Perl), and can see doing this in > a purely procedural way. But I'm not sure about how to do it in an OO way. > Do I represent each image as an object? What attributes should the objects > have? Read the books /Test-Driven Development/, /Refactoring/, and /Design Patterns/. Then write whatever works. When you refactor it, try to DRY the code up - meaning Don't Repeat Yourself. The fewer lines of code your program has, the more likely your objects have merged their common behaviors into base classes, and their specific behaviors into derived classes. The second link on my website, TDD, shows a long list of my various tutorials on OO design and implementation. I generally try to show the thought process that leads to emergent designs. -- Phlip http://www.zeroplayer.com/