teaching OO design / send non-primitive message / writing functions -
09-14-2007, 12:05 PM
I figured out a solution to my previous problem. You can set a variable to the top object in the list, then remove the object from the list. So this is a kludgy way of pulling an item off a list to send a message to.
Here's my problem: how do I send that object a non-primitive message?
It seems that when it comes to programmer-defined methods, you can only send one if you know the actual object you're going to send it to. For example, I can say "hanoiTower1.push," if I've written a push, but I can't send the "push" message to whichever tower I'm standing in front of if I happen to store that in an "object" variable -- I can't figure out if there's a way to be more specific than "object" (e.g. variable type= hanoiTower, not object) or to "cast" that object variable.
Having variables uncastable and confined to being a root "object" type makes it very difficult to create OO designs.
So I'm feeling very panicky about how I'm going to teach design to my students. I really don't have a sense of it. It's definitely not OO. The examples in the two texts I've read imply that it's OO and skirt around these issues. What paradigm should I be following?
Oh, and I'm having trouble with functions. It seems you can't use the regular list functionality within a function. (e.g. list.remove item from position) So, when I was writing my "pop" method, for example, I couldn't actually remove the item from the list in that function. I also couldn't copy/paste that command from a method, where I *was* allowed to access the normal list functionality. Is there a reason that functions can't do anything with a list variable? This is odd. You also don't have the "do in order" construct when creating a function.
Any advice is greatly appreciated!
Thanks,
Maggie
|