View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sp2002 Midterm Review: OO Theory

Back to Spring 2002 Midterm Review


1. A class is a template for an object. An instance is an object created from the class template.
2. An instance method depends on having an instance of that object. Things like display, goto, turn, rotate, that would have no meaning without an instance of an object. A class method has a meaning even when there are no instances, for example new, or clearWorld.
3. "Every time you create an instance of a class, the runtime system creates one copy of each the class's instance variables for the instance. You can access an object's instance variables from an object..."
"The runtime system allocates class variables once per class regardless of the number of instances created of that class. The system allocates memory for class variables the first time it encounters the class. All instances share the same copy of the class's class variables. You can access class variables through an instance or through the class itself."
4. Prototype inheritance in a way makes a unique class for each object that is created. It will inherit everything from it's prototype, and reflect changes made to the prototype. The problem is that prototype is just one instance of an object. If you make a redfish and a bluefish, and make pinkfish using the redfish as the prototype, then you make changes to redfish, pinkfish will change. but if you make changes to bluefish, pinkfish will remain the same. there isn't a way to change all of them, unless they were all prototyped from some oldfish. And in that case you better not loose that oldfish.

So, it's easy to make a bunch of objects using prototyped inheritance, but it's just as easy for them to get out of control.
Hank Wilde

1. A class is a prototype for a instance. An instance is the actual object of a class.
2. An instance meethod is affected only by the instance. Each instance has its own unique copy. A class method is one which is common to all instances of that class.
3. A class variable is a unique variable that is manipulated by all instances of a class. An instance variable is a variable that each instance gets its own copy of. Changing an instance variable only changes its value in that instaance, while changing a class variable changes its value in all instances.
4. If I am right, prototype based inheritence just gives a structure outline for each class. That is just method stubs are included in the prototype. The prototype cannot have instances. A class however can be subclassed. Subclass chooses which methods to override or overload and keeps the superclasses methods that the subclass did not change.

Randy Rockinson

I'm not quite sure what some of those mean: "A class is a prototype for an instance"? "An instance method is affected only by the instance"? Could you try re-phrasing? #4 is definitely wrong. Mark Guzdial

Let me try to clarify.
1. A class is a blueprint for some data structure or model, while an instance is the actual implementation of that blueprint.
Example: Car blueprint is the design specs for a car, while the actual vehicle you drive is the implementation of that design.

2. A class method is a method that is handled by the class. In squeak it would be a message sent to the class, like new, rather than to the instance. The instance method is one encapsulated by the instance. In squeak this is a message sent to the instance and not the class.

As for four, I have no idea. I just tried to stimulate a response from someone who may know. Hope this cleared it up a little.

Randy Rockinson

4. In a prototype-based architecture, objects with active data values act simultaneously as class definitions, and these objects can be inherited from to create more objects. Data values may or may not be inherited.

In the standard class-based architecture, classes exist which are simple type definitions, and it is invalid to call their methods except for class methods, and they have no data and consume no memory. Instances are then created of those classes, and those instances contain active data which can be operated on by services, but nothing can be further derived from those instances.

Prototype-based architectures have the advantage of ease-of-use, since they involve less creation of abstract entities and more of concrete structures with actual attributes; it's been shown that people are confused by the class/instance distinction in class-based architectures. However, prototype-based architectures also result in messier and less maintainable, as well as insufficiently static systems that can lead to long-term problems.

Derrick Coetzee

4. A prime example is the little model car we made in class. We made a car object with the paint tool, then we added a joystick. If we then copied the car, we would have an identicle car that responds to the joystick (I tried this). The car we drew is an Instance and has its own variables, but another instance can be created from the first car. The advantage is that painting the car was easy, the disadvantage is that the code is obfuscated.

Link to this Page