Alice 3 for starters. -
02-22-2011, 03:09 PM
It is difficult to answer because some of this is ambiguous.
"What are classes?" Do you mean specifically in Alice3 or is this just the only context in which you encountered them?
I'll assume the latter, so skip this if you know it already. You don't need reminding that computers store everything as binary, which is basically a numerical representation. If you have access to binary you can do pretty much any computational operation on it, whether it is sensible or not. Suppose you have an aircraft, and part of the software controlling it will raise the undercarriage. You want to do that when you are off the ground, or it gets expensive. Whether the undercarriage is up (1) or down (0) is just one bit in this example. But so is turning on the fuel light. So you make a mistake in coding, turning on the fuel light doesn't, instead it drops the aircraft on the runway.
So then you decide that what you need are data types. You need integers, strings, and booleans, so you can't make this kind of mixup so easily. But they are still too basic, and not very descriptive. So then someone comes along and says, "all these lights, and undercarriages, and ejector seats, they are all TYPES, and you can only do certain things to them. You can't strap yourself into a light". So you get "strong typing", and the operations the language will allow are restricted to certain things, and you get an error if you use the wrong one.
So then someone else comes along, and says, "Look, all these operations that can only be done to lights, and all the ones which can only be done to ejector seats: it really only makes sense to define them inside the type, actually have them belonging to the type itself. Then you can think of the things as OBJECTS, rather like in the real world. You can have cars, and planes, and engines.... And the operations are methods."
But there are lots of different types of car, or automobile. There are sports cars, small cars for cities, estate cars or station wagons, etc. They all have an essential "car-ness" about them. So they are all in the CLASS of car. And they all get the ability to be driven, have engines, etc. But now there are subclasses of car, sportscar, etc. And the things you can do to them, drive, park, crash (oops!) are methods. The subclasses are more specific than the general car. But you can define a new subclass without having to rewrite all the common stuff again. The subclass "inherits" this from its more general parent.
So this means that one answer to "Where are the methods?" is that they are inside the class, or its parent class (the one of which it is a subclass).
In Alice 2, the methods could not be defined for a person. If you wanted RoomMate to have the same abilities as LunchLady, you'd have to define the method twice. You should be able to define it in Person, so that all people get it.
"Restricted Scope": I'm not sure about this. It could be that the scope is dependent on whether you are defining for a class or a subclass. Or it might be talking about whether the things are in the scope of the Alice 3 project at the moment, and will not be included until they are. Or it could be a language feature I don't know about.
Hope that is useful, and not too inaccurate.
|