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

Sum2003 Midterm Review: Definitions

1) Inheritance: Objects can get data (attributes/variables) and behavior (methods) from another.

All Dogs and Cats are Animals, so Animal is the super/parent class and Dog and Cat are the child classes. Animal has a method called noise and an attribute called fur. Each instance of Dog and Cat set thier own values for fur and override the noise method to say "bark" or "meow" respectfully.

2) Delegation: The activity of asking another object to perform a service for the original object.

The Box instance delegates the responsibility of drawing to the Pen instance.
this is delegation. It is just mislabelled Barbara Ericson

3) Polymorphism: Having the same message perform approximately the same functions on different data.

Adding two integers and adding two floats is different at the machine level, but it uses the same message, aka, the '+' message.

4) Encapsulation: The concept that objects have their own data and behavior which cannot be messed with by another object without the given object's permission.

From the Box example in the book, Joe and Jane are both boxes with a name, one cannot change the name of either instance without obtaining permission to use either object. If the setName message were private, then another object would not have permission to use that method, even if it had access to the Joe or Jane instances.

5) MVC Paradigm: Models define the world, Views are what the users see (the GUI), Controllers handle the user input (mouse clicks, key presses, etc)

The Clock program in the book is an example of this paradigm.
Clock class = model
ClockWindow class = view
ClockButton class = controller

Good Answers Barbara Ericson

Isn't #2 the definition of delegation? :)



What is an example of aggregation?

So an example of aggregation would be if you have a block of code that gets reused quite a bit you would aggregate it out into say a separate function. Aggregation is the act of pulling common code out into a function for easy editing and readability. Aggregation is part of the refactoring process.

Or if you want something visual:
unaggregated:

int main(void)
{
double a = rand();
double b = rand();
double c = 0;

double d = 5;
double e = rand();
double f = 0;

double g = 0;

c = (a + b)/2;

f = (d + e)/2;

c++;

g = (c + f)/2;

printf("%f\n", g);
}

aggregated:

double average(double x, double y)
{
return ((x + y)/2);
}

int main(void)
{
double a = rand();
double b = rand();
double c = 0;

double d = 5;
double e = rand();
double f = 0;

double g = 0;

c = average(a, b);

f = average(d, e);

c++;

g = average(c, f);

printf("%f\n", g);
}

(note: above code is easier to read in edit mode i.e. i forgot how to do tabs in html)

1. Inheritance is when a child class (subclass) gets all the data and behavior from the parent class. Child class can override the methods in its parent class.

2. Delegation is asking the object to perfom some service for another object.

3. Polymorphism is when a variable takes on different types at runtime. One message performs same functions on different data.

4. Encapsulation is having data in one class that no other object can mess with. You know who is responsible for it.

5. MVC (Model-View-Control) paradigm allows for creating object-oriented and maintainable software. Model is the object from the problem domain (data and behavior is stored). Views are the objects the user interacts with (buttons, text area). Controller collects user-interface events and gives them to view or to the model.
~Sabina Karkin
good answers except for no examples here Barbara Ericson

Link to this Page