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

Steven Akins

Writing Code:

fibonacci: nth
    (nth < 0) ifTrue: [^self error: 'The nth term must be a non-negative integer'].
    (nth < 2) ifTrue: [^1]. "This handles one or zero, seeing as how anything less than zero has been handled already."
    ^(((fibonacci: (nth - 2)) + (fibonacci: (nth - 1)))


Class Based Inheritance:

As in most languages, a class is code that defines a self contained object, often similar to an object in the real world. That class is rarely used on it's own in object oriented programming other than for creating instances. An instance is an actual usable form of a class that has it's own specific space in memory for it's variables. In smalltalk, as in other languages, instance variables are variables defined by the class, but each instance has it's own copy. Class variables, on the other hand, are shared by all instances of that class, so the value remains the same throughout. Similarly, instance methods are used by instances of a class and can access both instance variables and class variables, while class methods require no instance and can be called just using the class name, but cannot access instance variables, because there is no instance.


Link to this Page