OO style tutorials?

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.

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?

So the question is: Are there any tutorials or resources that go more into the appropriate use of OO programming, strategies for structuring classes, rather than the nuts and bolts of creating objects and such?

Paul Archer

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.

So the question is: Are there any tutorials or resources that go more
into
the appropriate use of OO programming, strategies for structuring
classes,
rather than the nuts and bolts of creating objects and such?

Paul Archer

Hello Paul,

Your problem seems to be obvious. It is hardly possible to grasp such
concepts without proper training. Your project feels like a good way to
get going. Why don't you just dig in by yourself and come back with more
questions? Experiment by yourself. Truthfully, if you have read several
books already, the last thing you need is yet-another-something-to-read.

Ah. The heck. Have you read yet http://www.ruby-doc.org/ ? Click on the
link "An on-line copy of the first edition of the book Programming Ruby,
by Dave Thomas."; it's a good starter.

Regards,
Ian.

···

--
Posted via http://www.ruby-forum.com/.

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/

My first encounter with OO programming was with Java, and I found the Sun Java tutorial quite handy for explaining the basic ideas:
http://java.sun.com/docs/books/tutorial/java/concepts/index.html

I should also declare that I'm a pretty lousy programmer, and throughout Uni I had difficulty understanding the need for UML[1], CRC[2], Design Patterns and various other OO design jargon. But after 8 odd years working in the commercial world they began to find their place in my world. The understanding I came to is that there isn't a perfect tutorial for everyone because it depends a lot on your experience. Stuff that made no sense to me 8 years ago (and indeed seemed overwhelmingly complicated) makes perfect sense today.

That said I quite like CRC as a simple tool to help you think along the right lines.

I suspect beyond that you probably want a good UML or Design Patterns book. I don't have any recommendations but hopefully someone else on this thread will. :slight_smile:

yun

[1] http://en.wikipedia.org/wiki/Unified_Modeling_Language
[2] http://www.agilemodeling.com/artifacts/crcModel.htm

···

At 04:48 PM 8/03/2009, Paul Archer wrote:

So the question is: Are there any tutorials or resources that go more into the appropriate use of OO programming, strategies for structuring classes, rather than the nuts and bolts of creating objects and such?

--
                                     (__) Share what you know.
Yun Huang Yong `\------(oo) Learn what you don't.
gumby@mooh.org || (__) --'
goosmurf@yahoo.com \|/ ||w--|| \|/
--

* Paul Archer <paul@paularcher.org> [2009-03-08 14:48:36 +0900]:

So the question is: Are there any tutorials or resources that go more
into the appropriate use of OO programming, strategies for structuring
classes, rather than the nuts and bolts of creating objects and such?

Design Patterns in Ruby by Russ Olsen is what I would recommend reading

saji

···

--
Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 saji@apcc21.net
KOREA

Thanks very much to all that responded. I'm frankly a bit overwhelmed by both the quantity and quality of responses. I feel a bit like the singer in The Police's "Message In A Bottle": "Woke up this morning/don't believe what I saw/Hundred million bottles washed up on my shore."

@Ian: You're probably right, I need to dig in and get started. It's not that I'm a perfectionist, exactly--but I have this "I've got to do it right the first time" mentality that I need to get past.

@Phlip: I guess thinking of it as refactoring, rather than just "redoing my poor first attempt", that'll help. (See above about wanting to do it right the first time.) And thanks for pointing me to your website.

@Yun: What's CRC?

@Udayanga: thanks, I'll check out the "Head First" book.

@Saji & Rick: And the "Design Patterns" book, too.

@Robert: The OO Encyclopedia looks like a good reference. (Might even find out what CRC is. :sunglasses:

@Paul: So get to work.

thanks, all!

Paul

···

On Sun, 8 Mar 2009, 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.

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?

So the question is: Are there any tutorials or resources that go more into the appropriate use of OO programming, strategies for structuring classes, rather than the nuts and bolts of creating objects and such?

Paul Archer

* Paul Archer <paul@paularcher.org> (2009-03-08) schrieb:

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

That's a file, right?

and renames them an 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.

I don't see a reason to do it any other way. One might create some OOP
concepts for doing that, but that would be more code than the simple
loop of the "procedural" way.

It's a too simple task for learning OOP. Just use objects when you see
the need for it.

mfg, simon .... l

Hi Paul,
I too agree with Ian. Obvious reason might be lack of experience in these OO
design concepts . OO is not about creating classes and objects but how you
apply it in real world scenarios efficiently. In my personal opinion i do
not recommend you to use a Ruby Language book as a gateway for grasping OO
,coz it might be more concentrating on Ruby rather than OO. I prefer , you
use a good introductory book such as 'Head First Object-Oriented Analysis
and Design' which would give you a great understanding to polish off your OO
concepts..

Regards
Udayanga

I should also declare that I'm a pretty lousy programmer, and throughout Uni I had difficulty understanding the need for UML[1], CRC[2], Design Patterns and various other OO design jargon. But after 8 odd years working in the commercial world they began to find their place in my world. The understanding I came to is that there isn't a perfect tutorial for everyone because it depends a lot on your experience. Stuff that made no sense to me 8 years ago (and indeed seemed overwhelmingly complicated) makes perfect sense today.

Took me some time, too. My first OO program was horrible and I believe it took at least a year until I managed to grasp it - at least half way.

That said I quite like CRC as a simple tool to help you think along the right lines.

I also believe that CRC is a good tool because it is quite simple and keeps you focused on important points. I'd say though that it still takes a bit more to craft a good OO application. But CRC is very useful as it will also help to not lump too much functionality into a single class.

I suspect beyond that you probably want a good UML or Design Patterns book. I don't have any recommendations but hopefully someone else on this thread will. :slight_smile:

I always recommend "Object Oriented Software Construction" by Bertrand Meyer. It is not exactly a tutorial but rather an encyclopedia where you can look up whatever OO term you encounter somewhere else. Meyer really has a profound understanding of all the different aspects of OO and ways in which it can be used.

http://archive.eiffel.com/doc/oosc/page.html

Kind regards

  robert

···

On 08.03.2009 10:28, Yun Huang Yong wrote:

I'll give that a hearty second. Russ does a very good job of teaching OO
design from a Ruby perspective.

I strongly believe that although there might be a few universal truths, most
good OO design needs to take the characteristics of the language into
account. If you learn OO from a Java tutorial, you're going to speak Ruby
with a Java accent. Object Oriented Software Construction will leave you
with an Eiffel accent. The Gang of Four Design Patterns book, although it
purports to be "language neutral" at least for the popular OO languages back
in 1995, is strongly influenced by C++.

Russ' book is noteworthy because, although it's inspired by the GOF book, it
points out how the choice of language is a real factor in the choice and
expression of design pattern languages.

···

On Sun, Mar 8, 2009 at 8:00 AM, Saji N. Hameed <saji@apcc21.net> wrote:

* Paul Archer <paul@paularcher.org> [2009-03-08 14:48:36 +0900]:

> So the question is: Are there any tutorials or resources that go more
> into the appropriate use of OO programming, strategies for structuring
> classes, rather than the nuts and bolts of creating objects and such?
>

Design Patterns in Ruby by Russ Olsen is what I would recommend reading

http://www.amazon.com/Design-Patterns-Ruby-Addison-Wesley-Professional/dp/0321490452

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Paul Archer wrote:

@Ian: You're probably right, I need to dig in and get started. It's not
that I'm a perfectionist, exactly--but I have this "I've got to do it
right the first time" mentality that I need to get past.

I do understand your point. And it's not a bad thing at all. You should
however just keep in mind to balance passive and active learning. It's
also a great opportunity to write few lines of code and then go back to
your books, and repeat the process. It's a good way to bind practical
and theoretical knowledge together. It will lit light bulbs in your head
while helping you to better grasp other concepts, that you're currently
reading on. This process will also allow you to focus on weaker areas
(theoretical or practical), which you understand more or less. Isn't it
a wonderful way to learn? :slight_smile:

@Yun: What's CRC?

Well, keep us posted.

Ian.

···

--
Posted via http://www.ruby-forum.com/.

Paul Archer wrote:

@Yun: What's CRC?

Maybe these links are useful:
http://c2.com/doc/oopsla89/paper.html
http://c2.com/cgi/wiki?CrcCard

···

--
domain name: ono
TLD: .com

Rick DeNatale wrote:

I strongly believe that although there might be a few universal truths, most
good OO design needs to take the characteristics of the language into
account. If you learn OO from a Java tutorial, you're going to speak Ruby
with a Java accent.

Very true, and I'm glad to see this point made.

Object Oriented Software Construction will leave you
with an Eiffel accent. The Gang of Four Design Patterns book, although it
purports to be "language neutral" at least for the popular OO languages back
in 1995, is strongly influenced by C++.

???

The GoF book has strong influences from Smalltalk and Java. C++ OO is a completely different beast. The GoF don't even mention templates, nor static polymorphism.

Most self-proclaimed "pure OO" schools of thought represent only Smalltalk-style OO, based heavily on runtime indirection. UML only supports templates as a kind of necessary evil, and still lacks any support for concepts (where "concept" is a technical term, with a specific meaning in C++). The GoF book is in this vein.

Bare C++ has far less support for OO at runtime than (say) Ruby, but dramatically better support at compile-time. For example, whereas multiple inheritance is kind of a dark art in most OO schools of thought, C++ has wonderful support for it, and deals very cleanly with reconvergent inheritance hierarchies ("diamonds"). If you come from a OO background, and want to learn C++, the best way is to temporarily forget everything you thought you knew about OO.

Btw, a related topic came up today in comp.lang.c++, about translating GoF terminology to C++. I mentioned an example that fits, IMO, the decorator pattern: An output iterator performs a given operation on each output value, then passes the result to another, underlying iterator. In GoF terminology, Component, the ConcreteComponents, Decorator, and the ConcreteDecorators are all "classes." In the C++ implementation, though, Component is the OutputIterator concept, the ConcreteComponents are the specific types of the underlying iterators, the Decorator is a template (parameterized by ConcreteComponent and by the operation to be performed on output values), and all ConcreteDecorators are instantiations of the template.

I would not necessarily say so. It just happens that Eiffel is the
language which has the richest zoo of inheritance options (including
private inheritance, i.e. without maintaining "is a" relationship)
that I know. And Bertrand Meyer not only presents concepts but
verbosely explains them. So I'd say you can understand them
independent of language. It may be though that you benefit most from
this book if you have some OO background already.

Kind regards

robert

···

2009/3/8 Rick DeNatale <rick.denatale@gmail.com>:

Object Oriented Software Construction will leave you
with an Eiffel accent.

--
remember.guy do |as, often| as.you_can - without end

The GoF book has strong influences from Smalltalk and Java. C++ OO is a
completely different beast.

He probably assumed a strong c++ influence because many/most examples
are in c++. IIRC (but I could be wrong of course) the book (1994)
doesn't mention Java (1996).

The GoF book has strong influences from Smalltalk and Java. C++ OO is a
completely different beast.

Is that why GoF was published in '94, before Java was released (in '95), and has C++ examples?

John V. is no longer with us). And there's not nearly as much Smalltalk
influence as there should be, Ralph Johnson admitted as much when he
autographed my copy.

As for not using things like templates etc. in C++, I don't know whether or
not those features were commonly available if at all when the book was
written.

···

On Sun, Mar 8, 2009 at 1:34 PM, Leo <minilith@gmail.com> wrote:

> The GoF book has strong influences from Smalltalk and Java. C++ OO is a
> completely different beast.

He probably assumed a strong c++ influence because many/most examples
are in c++. IIRC (but I could be wrong of course) the book (1994)
doesn't mention Java (1996).

No, I didn't assume, I knew because I know all four authors (or knew, since

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Phlip wrote:

The GoF book has strong influences from Smalltalk and Java. C++ OO is a
completely different beast.

Is that why GoF was published in '94, before Java was released (in '95), and has C++ examples?

My apologies. Kindly replace "Java" with "attempts to layer static typing onto SmallTalk."

Rick DeNatale wrote:

As for not using things like templates etc. in C++, I don't know whether or
not those features were commonly available if at all when the book was
written.

They were. See also:

Anyway, the point I wanted to make was that the GoF book presents a very different take on OOP from modern C++.

How do I unsubscribe?

···

-----Original Message-----
From: Jeff Schwab [mailto:jeff@schwabcenter.com]
Sent: Monday, March 09, 2009 4:38 PM
To: ruby-talk ML
Subject: Re: OO style tutorials?

Rick DeNatale wrote:

As for not using things like templates etc. in C++, I don't know whether

or

not those features were commonly available if at all when the book was
written.

They were. See also:
http://www.amazon.com/Scientific-Engineering-Introduction-Advanced-Technique
s/dp/0201533936/ref=sr_1_1?ie=UTF8&s=books&qid=1236634543&sr=1-1

Anyway, the point I wanted to make was that the GoF book presents a very
different take on OOP from modern C++.