Sunday, 20 November 2005

Object virgin?

Recently, I have mostly been writing up some lecture notes on objects and classes. Now, an object is really just a bunch of data and some operations to manipulate that data. So, lists and operations to add and remove elements from them, whatever.

So, how to explain that to first year programmers? Well, I suggest not by introducing a "Pizza making robot" or a "Person" object. These are not entities which easily reduce to the "data and operations on it" model. I don't know what a person is, but I'm sure it's not just a collection of data and algorithms, even in a very abstract sense. As John says, a Person object really ought to have methods called "respire()" and "excrete()", but the ones in text books usually just have lame things like "get_age()".

In the end, students seem to respond better to programmatic examples (even if they are quite abstract) than really fake examples that are supposed to be "relevant" to them. Better to give them a PrintServer than a Person.

No comments:

Post a Comment