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

CoWeb Assignment 1 #2

CoWeb Assignment 1

Class-Based Inheritance (1 point)

What is a class?
A class represents a concept. It defines how to define new objects of the same kind. It defines the variables and methods common to all objects of the same kind.

What is an instance?
An instance is an object of a particular class.

How do the two relate?
A class is a blue-print for an instance or an object is an instance of a class.
So we create objects through instantiating classes.

In Smalltalk, what is the difference between class variables and instance variables?
A class variable is a variable associated with a particular class as rather than its instances. They allow common sharing of information across a range of subclasses, and they start with upper case letter. Class variables are good for keeping constants, which are the data that never change across different instances of a class or for variables that we want them to change for all instances once they change. Also a class can keep track of all of its instances through instance variables.
An instance variable is a variable that is associated with an instance of a class (an object). So every instance (Object) of the same type (same class) will have these variables.

In Smalltalk, what is the difference between class and instance methods?
Class methods are behaviors that only refer to the class itself, so they only refer to the object class. But instance methods refer to the instances of the class.
Class methods start with capital letter, but instance methods start with lower case.




Message Passing (1 point)

What is message passing and how does it fit into the way you program in Smalltalk?
Everything in smalltalk is through message passing. Each message is of the form of .
So in a line of code, the first object is always the receiver object and anything after that is the message.


How does message passing work together with the class-based inheritance?
In a class hierarchy, the parent class has a method that all of its children have that also. So late binding and inheritance hierarchy play an essential roll in message passing.
When you pass a message to two different object of the different child’s of a parent class, at compile-time smalltalk finds out that the parent classes, and the classes themselves have that method and at run-time it decides which instances of the class are using that method. So if child of a class doesn’t have the method that the parent class has, at compile time small talk goes up the hierarchy and finds out that this message can be related to this object, and at run-time it runs the method of the parent on the instance of the child.

What are some of the advantages and disadvantages of method passing?
The advantage of message passing is it makes it very easy to program in smalltalk. It gives a good understanding of objects and messages.
Also message passing is associated with late binding so all the messages will be queued in the system stack. At the same time it increases the working size since its queuing the messages and it can be very inefficient.

=========
Amin Ali
gtg741m@mail.gatech.edu

Link to this Page