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

Sp2000 Midterm Review: O-O Systems

Review at Midterm Review - Sp2000.

Michael Emard and Michelle Burnett bring you the following answer

(a) A class is a general model of a real world object, such as a chair. An instance is a particular real world object, such as myChair or michellesChair.

(b) A class method is one that can be used without an instance of that particular class. An instance method is one that must be called upon through an instance. A good example would be a calculator class. You could have a class method add(num, num) that would return .. (you know what... if you dont' know what this is going to return you are goofy). Anyway, you don't need an instance of calculator to use the add method. One could decide to use several calculators at once. Calculator could also contain items such as color. You could create a new instance of Calculator and set the color using an instance method.

(c) Class variables are not used very often but they can be explained with the calculator example. If you had a few instances of calculator and had color as an instance variable, all calculators could be different colors. If you declared color as a class variable all calculators would have to be the same color. Color could change, but it would change for every instance.

(d) I'm gonna take a guess here and say that prototype systems are like simula and sketchpad where you can have a master prototype and other objects can mimic this master. Class-based object systems bring inheritance and hierarchy subclassing into the picutre.


(a) I'd like more detail than a definition, please. What does a class do? What is the relationship between an instance and a class? What does the instance get from the class?
(b) No, that's a Java explanation. What's the Smalltalk explanation?
(d) But what are the strengths and weaknesses?
(I completely agree about one or two answers, but you're going to need multiple answers to some of these.)
Mark Guzdial

does anyone know the answer for part (d)? all i can come up with is a regurgitation of what mark said in class: protoyping is easier for rapid development and small projects. protyping is conceptually simpler. class/instance systems, therefore, require more work, but scale better. ??

(a continued) Classes are stuctures that hold a collection of methods and data. Classes define the implementation of a set of objects that all represent the same kind of item. The individual objects defined by a class are called instances.

(b) Class methods are ones that do things such as making new instnaces of itself. Instance methods are the ones we use to manipulate a particular instance of a class.

Class methods can do more than just make new instances. Consider "Newspaper start"
Michael Emard _

Here's an example of prototype vs. class based objects used in an early OOPSLA talk on the subject. Let's say that Indian Elephants have short trunks and African Elephants have long ones. (I have no idea if this is true, but pretend.) Let's say that Fred is an Indian Elephant (IE) and Mabel is an African Elephant (AE). Imagine that you met Mabel first, and later met Fred, and when you met each, you tried to model them.

PROTOTYPE SYSTEM: You meet Mabel and say "That's an Elephant!" You meet other AE's, and you model them by instantiating Mabel. Later, you meet Fred. You instantiate Mabel to make Fred, but you override trunk length to make it short. Now all IE's will instantiate off Fred.

CLASS SYSTEM: You meet Mabel, create an Elephant class, then instantiate your model of Mabel as an Elephant. You create other instances of Elephant. Then you meet Fred. Now, you can realize that there are different kinds of elephants, so you create the subclasses IE and AE, make Mabel a kind of AE, and Fred a kind of IE.

Which do you want to maintain?

Other question: Who understands class methods? Who understands instance methods? Ditto for variables.

Mark Guzdial

a) class - describes the implementation of a set of objects that all represent the same kind of system component.
instance - the individual objects described by a class.

b) Difference between a class and instance method
a class method can be used without a particular instance of that particular class.
an instance method has to be called upon through an instance.

c) class variable vs. instance variable
An instance variable is accessible to one specific instance of a class, meaining it only can exist in one object.
On the other hand a class variable is accessible to all instances of a particular class.
ie. if a class variable for a CD Player was "RadioStation",
and it was set once to 99x. Then all cd players would be set to 99x.

A prototyped based system is difficult to change because everything is assumed to fit the prototype derived from a specific instance of an object. This produces data which is often repeated, causing unneccessary additions to memory.

A class-based system can undergo rapid change to its structure via such devices as polymorphism, where the programmer can maintain the previous attributes of the master class, and add detail with the attributes specific to their respective subclasses.

No, prototype-based systems actually consume LESS memory, and they can also do polymorphism. And you keep explaining class methods in terms of Java ("can use it when there are no instances"). WHO UNDERSTANDS CLASS METHODS? That's the critical part. Mark Guzdial

From what I understand from the Smalltalk-80 book, class methods are defined in the metaclass of a particular class. All classes are instances of their metaclass. Whenever you call a class method, it looks for it in the metaclass of that class.
Kapil Chandra

That's all true, but darn hard to understand :-). Basically, class methods are understood by the CLASS OBJECT ONLY! Doesn't matter if instances of the class exist or not. Instance methods are understood by INSTANCES ONLY. That's why "joe clearWorld" and "Box grow: 10" both fail. Mark Guzdial

Link to this Page