From: Lloyd Linklater Date: 2007-12-14T21:30:17+09:00 Subject: Re: Newbie Question: What is a class for? All the other guys said lots of cool and useful technical stuff. Let me use history to give some of the ideology. In the procedural days, programs became unmanagable when they got over 1/4 million lines or so, though 1/2 million line programs were not unheard of. Well, the notion of how to bunch things into blocks did for software what the chip did for hardware. The software version of a chip is the class. You make a class that has some characteristics foundational to its descendants. You program in the things that cover all the basics. Then, you add things as you get increasingly specific. e.g. You want a class for dogs and cats. Well, they are fairly different so what do they have in common? class mammal # stuff end class four_legged < mammal # stuff end class cat < four_legged # stuff end class dog < four_legged # stuff end Note that if you add things in the base class, mammal in this case, it trickles down to all descendants. This is VERY handy in many ways. By coding this in pieces, you can more easily keep it all in your head and, therefore, write far more complex programs with far more simplicity. There are, of course, things that lend itself to art rather than mere technique in class design, but writing classes so that they are easily used is a good thing to know. Consider Ruby's approach. You can do something.to_s all over the place. That takes planning. Not TOO much planning, but some. That means that it had to be thought through and included in all descendants. So, classes makes life simpler when there is, in actuality, a good deal more complexity behind the scenes. p.s. There are plenty of tutorials on this. The first one ask.com gave me is http://java.sun.com/docs/books/tutorial/java/concepts/index.html -- Posted via http://www.ruby-forum.com/.