Nice metaphor for object-oriented concepts

See, this question doesn’t make sense: An object can be an abstract data type with attributes just as much as it can be a locus of control with methods and mutable state. In fact, I think it makes more sense to teach the object-as-ADT first to get them used to the idea of something that only exists in the code simulating something in the real world, and how much easier that makes writing software using those things.

Yesterday, my professor gave us a good lecture on generics by using prison cells and thieves (and pickpockets as a derived class of Thief). I found that to be pretty neat.

I remember a Programming Languages class where the OO language was taught using the animal metaphor.

The cool thing was that the CS department wrote a framework app called “Savannah” that did all the heavy lifting, leaving the animal for the student.

You would override the animal interface to your heart’s content, saying what kinds of sounds the creature would make, what was its representation (ASCII art) on the screen, how fast it moved, and how it would behave when it saw another animal close by.

Once you finished implementing a few animals, it was a snap to plug them into the Savannah application and watch your little ASCII-art creatures strolling about in their own way, interacting with other creatures, all controlled by the Savannah framework.

This was neat because students only had to implement an animal class and didn’t have to write loads of other code to see it doing its stuff.

Maybe the old kangaroo-story could be useful?

Were Armed Kangaroos Added to a Military Combat Simulation Program? | Snopes.com (half-true)

Cars are a bad choice for modern 16 year olds because to most of them a car is a black box.

You need something where the students can easily apprehend 2 or 3 layers of derivation to get to the “surface” class which they will derive from in their exercises.
The funny thing is industry is now driving a bit away from classic OO. Deep inheritance is inflexible & subject to *fragile base class *syndrome. With IOC, dependency injection, etc., we’re going back towards objects as property containers, not method containers.

I’m currently eyebrows-deep in Team Fortress 2, so I always try to think of everything in terms of TF2.

Not exactly sure how you’d use OO in that context, though.

[tangent]Gotta admit that in the many years since I studied OO in college, I have rarely used it to the extent that the OO evangelists were hoping.

In the majority of cases, I have found myself using loads of Java interfaces, and extending interfaces. Extending classes has been quite rare, reserved mostly for Java GUI work, extending pre-existing framework base classes. And in the latter example, it is usually a provided abstract class that is extended, a class that was intended to be extended from the start.

Perhaps in the humdrum corporate coder world this happens because the Oracle databases that drive every part of our existence are designed first, by database designers, and do not necessarily fit weird object models well.

I don’t know if this is representative of what the average Joe does, but it has been my experience.[/tangent]

I just wish more things on my computer were treated as objects. I want to print the contents of a directory, like I print a speadsheet or a document or an email. Can’t do it because a directory is magically different than other things in my computer. :confused: I’d like to copy paste and edit a calendar entry - no can do since it’s magically differnt than everything else in my Outlook. Why can’t I copy the Moday weekly meeting with Team A and make a monthly Wednesday meeting with Teams A and B? Mailing lists: copy, paste, forward - all no go. Why?

Or am I just ranting against M$ again? As well as my own ignorance?

This is how I think of object oriented programing: you’re desiging a bunch of small programs, and then linking them to each other.

And the benefit is that you can change one part of the code without having to go back through the whole thing. And you can troubleshoot each baby program individually.

For an example, go to the Monty Hall thread in CCC. There’s a procedural javascript written by me, and an object-oriented Ruby program written by someone else. And look at which one more directly models the real world.