Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Discussion 4 - Chris Gray
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
- Chris Gray last edited on 14 December 2005 at 7:53 pm by c-71-56-42-154.hsd1.ga.comcast.net
- Fall 2005 Discussion 4 last edited on 6 December 2005 at 3:45 pm by r36h51.res.gatech.edu