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

Discussion 4 - Chris Gray

Discussion 4

1) What's a class? What's an instance?
2) What's the difference between a class and instance method?
3) What's the difference between a class and instance variable?
4) In the following Squeak code what type of method (class or instance) is "new" and what type is "initialize"?

joe := Box new initialize

1) A class is a grouping of variables and methods, the noun of Squeak and the blueprint for instances. An instance is a single version of a class with specific data. ie if Bob is a class and Bob1 and Bob2 are instances then Bob1 and Bob2 may have different attributes.

2) A class method affects the entire class whereas instance methods only affect that instance and are lost when we do away with the instance.

3) A class variable is the same across all instances of a class but an instance variable is private and unique. Changes to the class variable have an effect on all classes but changes to the instance variable do not affect other instance variables.

4) New is a class method and initialize is an instance. New is a part of the box class but initialize only applies to this one instance.

Links to this Page