# Nice metaphor for object-oriented concepts

**URL:** <https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551>\
**Category:** In My Humble Opinion\
**Created:** [November 22, 2010, 5:44pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551 "2010-11-22T17:44:06Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [November 23, 2010, 1:41pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/21 "2010-11-23T13:41:00Z")

</div>

> [@tdn](#):
>
> What function does a card have?

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.

---

<div class="post-metadata">

**Author:** ![Agent\_Foxtrot](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Agent\_Foxtrot](https://boards.straightdope.com/u/Agent_Foxtrot)\
**Post date:** [November 23, 2010, 3:14pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/22 "2010-11-23T15:14:41Z")

</div>

> [@Mijin](#):
>
> A friend has recently asked if I could write an interactive app to help him teach his students basic object-oriented concepts (e.g. classes vs objects, encapsulation, inheritance, etc).
> 
> To cut a long story short, I’m not too worried about the coding side or making sure that the theory is all sound (and useful). But I can’t quite decide on a suitable metaphor.
> 
> I’ve seen many examples demonstrating inheritance with animals or polygons. And for designing a whole OO app, I’ve seen examples of managing a (book) library, say.
> 
> But these are all quite dry and I’m struggling to think of something a bit more engaging.
> 
> * * *
> 
> If I use any suggestions from this thread, I’ll credit the suggestor accordingly. Also, I’ll post my app here. 🙂
> 
> Finally, if anyone knows of any nice interactive apps already out there, by all means let me know. I’m helping my friend out partly to get a nice reference, but I’m not going to reinvent the wheel just to prove I can.

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.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [November 23, 2010, 7:17pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/23 "2010-11-23T19:17:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Staale\_Nordlie](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@Staale\_Nordlie](https://boards.straightdope.com/u/Staale_Nordlie)\
**Post date:** [November 23, 2010, 7:59pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/24 "2010-11-23T19:59:08Z")

</div>

Maybe the old kangaroo-story could be useful?

> [@](#):
>
> Mutant Marsupials Take Up Arms Against Australian Air Force
> 
> The reuse of some object-oriented code has caused tactical headaches for Australia’s armed forces. As virtual reality simulators assume larger roles in helicopter combat training , programmers have gone to great lengths to increase the realism of the their scenarios, including detailed landscapes and — in the case of the Northern Territory’s Operation Phoenix — herds of kangaroos (since groups of disturbed animals might well give away a helicopters position).  
> The head of the Defense Science and Technology Organization’s Land Operations/Simulations division reportedly instructed developers to model the local marsupials’ movements and reaction to helicopters.
> 
> Being efficient programmers, they just re-appropriated some code originally used to model infantry detachments reactions under the same stimuli, changed the mapped icon from a soldier to a kangaroo, and increased the figures’ speed of movement.
> 
> Eager to demonstrate their flying skills for some visiting American pilots, the hotshot Aussies “buzzed” the virtual kangaroos in low flight during a simulation. The kangaroos scattered, as predicted, and the Americans nodded appreciatively . . . and then did a double-take as the kangaroos reappeared from behind a hill and launched a barrage of stinger missiles at the hapless helicopter. (Apparently the programmers had forgotten the remove “that” part of the infantry coding).
> 
> The lesson? Objects are defined with certain attributes, and any new object defined in terms of the old one inherits all the attributes. The embarrassed programmers had learned to be careful when reusing object-oriented code, and the Yanks left with the utmost respect for the Australian wildlife.
> 
> Simulator supervisors report that pilots from that point onwards have strictly avoided kangaroos, just as they were meant to.

[Were Armed Kangaroos Added to a Military Combat Simulation Program? | Snopes.com](http://www.snopes.com/humor/nonsense/kangaroo.asp) (half-true)

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [November 25, 2010, 2:40pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/25 "2010-11-25T14:40:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotchan](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dotchan](https://boards.straightdope.com/u/dotchan)\
**Post date:** [November 25, 2010, 3:45pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/26 "2010-11-25T15:45:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [November 25, 2010, 4:44pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/27 "2010-11-25T16:44:51Z")

</div>

> [@LSLGuy](#):
>
> 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.

[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]

---

<div class="post-metadata">

**Author:** ![Typo\_Knig](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Typo\_Knig](https://boards.straightdope.com/u/Typo_Knig)\
**Post date:** [November 25, 2010, 6:10pm UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/28 "2010-11-25T18:10:07Z")

</div>

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. 😕 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?

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [November 26, 2010, 2:26am UTC](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551/29 "2010-11-26T02:26:25Z")

</div>

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.

[Previous page](https://boards.straightdope.com/t/nice-metaphor-for-object-oriented-concepts/561551.md?page=1)
