Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Discussion 4 - Ashley Durham
I answered the definitions question from Spring 2000.
Define each and give an example.
a. What is Inheritance?
Inheritance is a principle that allows object to re-use the same code. Objects utilize this object by extension from
another object. The object extended from is called the parent or superclass. The object doing the extending is called
the child or subclass. Suppose we have a class called Animal. All Animals have a size and color, and they can all eat and
sleep. Now suppose we want to create a Cat class. We can simply have Cat extend Animal. Now Cat also has a size and color
and can eat and sleep. The relationship between super and sub classes is often referred to as an "is-a" relationship. A
cat "is-a" animal.
b. What is Delegation?
Delegation is a principle in which one object delegates, or assigns, some of its responsibilities to another object.
This happens when a message is sent to object A. Instead of object A mapping that message to a method, it instead causes
a second message to be sent to another object, object B. For example, in our 'Joe the Box' example, when Box received a
certain messages, Box just sent these messages on to the Pen object. Therefore Box delegated to Pen.
c. What is Polymorphism?
Polymorphism is a concept in which the same message performs approximately the same functions on different data. For
example, when an object receives the message printIt, that object's print method is called. Although the result may be
nearly the same (a visual representation of an object that is able to be displayed on a transcript), the print method for
an integer is actually quite different from the print method for say, an array. However, the same message, printIt, got
approximately the same results for two very different data types, integers and arrays. This is polymorphism.
Links to this Page