SlideShare a Scribd company logo
Cs193i, Stanford                                                        Handout #28
Spring, 99-00                                                           Nick Parlante

                          OOP Concepts
(This is a CS108 handout on the basics terminology and structures of OOP.)

Object Oriented Programming, OOP, is the must influential paradigm of our
time. This handout summarizes the very basic style, elements, and vocabulary of
OOP that are common to all OOP languages. OOP languages can have their
obscure features, but the basic ideas of OOP are pretty straightforward.

Pre-OOP
In a classical compiled language like Pascal or C, data-structures and their
operations are arranged logically, but it is the programmer's duty to devise and
enforce these arrangements. Related functions tend to go in one file, but the basic
operation of matching of the right operation with the right type of variable
remains a programmer chore. In the best case, is mismatch will result in a
compile time error. In the worst case, such as with a mis-cast void*, a mismatch
will crash in some unpleasant way.

OOP
In OOP, the logical arrangement of the code is changed. Instead of an informal
arrangement of functions into different files, functionality is officially and tightly
grouped with the type that it operates on. The OOP style groups all the
operations together according to what they operate on — all the hash table
operations are part of the hash table class, all the string operations are part of the
string class. Put another way: if variables are nouns and functions are verbs,
then OOP divides up everything in to categories based on the noun.

Historically, there are many ways to structure code, but the OOP style has
proved to work quite well. OOP yields a pretty obvious decomposition and
facilitates code re-use. Most importantly, OOP keeps the role of client and
implementor separate. Keeping the client side separate from the implementation
side has a host of advantages. Don't just think "oh yeah, client separate from
implementor — too basic for me." It's not sexy, but it's useful. OOP formalizes
and enforces the separation. It no longer requires any special skill to keep them
separate; the language makes it the most convenient way to proceed.

The strengths of OOP help the most when writing large programs, programming
in teams, and perhaps most importantly, packaging up code into libraries for use
by others.

The Grail of Code Re-Use
One of the obvious goals of language design has been to make it possible, finally,
to stop re-creating common code for every project. Lists, hash-tables, windows,
buttons ... these are things that should not have to be re-created for every project.
For code re-use to really work, it must be easy to be a client of that code. OOP,
and Java and its libraries in particular, appear to be our best hope of finally
obtaining true code re-use.
2


The Clueless Client Test
The "clueless client test: a language has good support for code re-use if it is
possible to build a library of code, give it to a client who wants that behavior, and
that client can get the behavior from the library even if the client is clueless or a
little clumsy. The language should encourage the right client behavior and
discourage common client errors and politely alert the client if there is an error.
The DArray in C, for example, fails the clueless client test: the client needs to use
it exactly right, or it blows up in their face.

Class
The most basic concept in OOP is the Class. A class is like a type in classical
language. Instead of just storing size and structural information for its data, a
class also stores the operations which will apply to the data. Class = Storage +
Behavior. A class is like an Abstract Data Type in Pascal or C— it creates a logical
coupling between data and the operations on that data. Bundle the verbs with
their nouns.

Object
An object is a run-time value that stores state and belongs to some class. So if
classes are like types, then objects are like variables. Where plain old variables
just have a type, objects belong to a class, and so they automatically know what
operations they are capable of. The word "instance" is a synonym for "object."
The phrase "an instance of the string class" to identify an run time object of the
string class sounds better than "an object of the string class."

Message and Method
OOP uses "messages" instead of function calls. Sending a message to an object
causes that object to perform an operation on itself. In that case, the object
receiving the message and performing the operation is known as the "receiver".
The receiver looks at the message, figures out the appropriate operation to
perform, and executes that operation on itself. The receiver knows what
operations it can perform, because it knows its class, and the class defines all the
operations for its instances. The code corresponding to a particular message is
known as the "method" for that message. A message is just a string like "Pop()".
The method for Pop() is the code in the Stack class which is triggered by the
"Pop()" message. The C++ specific term for method is "member function".

// Traditional programming
// Call the Foo() operation, and pass it the data to operate on
Foo(x);


// OOP programming
// Send a "Foo()" message to the object -- the "receiver" of the message.
// The receiver gets the message, finds the matching method code in its class,
// and the method code executes on the receiver.
x ← "Foo()"


The method that executes depends on the class of the receiver. If you send the
Print() message to a Stack object, you get the Print() method in the Stack class. If
3


you send that same Print() message to a HashTable object, you get the (different)
Print() method in the HashTable class. It's what you say, and the class of the
receiver that you say it to.

Message Send Syntax
In Java and C++, the syntax for sending a message looks like appending the
message to the desired receiver with a dog:

x.Foo(); // Send the "Foo()" message to the receiver "x"


Receiver Relative Code
We say that "the method executes against the receiver." This just means that the
method code operates on the data of the receiver. So in code like the following...

x ← "RemoveAllElements"
y ← "AddElement(12)"


The receiver x is, apparently, going to remove all the elements it is storing, while
the receiver y is adding an element. The method operates on the receiver it is sent
to — x or y in this case. This makes methods different from plain C functions. C
functions operate on the parameters they are passed. Methods, on the other
hand, always have a receiver object to operate on. Parameters are only necessary
for extra data.

Encapsulation
"Encapsulation" refers to protecting the internals of an object from direct
manipulation by the client. The client can send messages, but the client cannot
change the bits in the object directly. In C , it's just a convention that the client
should not mess with or depend on the implementation of an Abstract Data Type
(ADT). With encapsulation, the compiler enforces the separation. The class
implementation can indicate which parts of the implementation are protected so
that client code accessing those parts will not compile.

Or put another way: the client cannot mess with the object's state — the client can
only send messages. The object's state is only touched by its own methods. Once
those methods are correct and debugged, the object can be given to any client,
and that client should not be able to perform an operation on the object which
puts it in an incorrect state. This depends on the methods being correct which is
still difficult. But when they are correct at last, the client should not be able to
mess things up.

Hierarchy
Classes in OOP are arranged in a tree-like hierarchy. A class' "superclass" is the
class above it in the tree. The classes below a class are its "subclasses." The
semantics of the hierarchy are that classes have all the properties of their
superclasses. In this way the hierarchy is general up towards the root and
specific down towards its leaves. The hierarchy helps add logic to a collection of
classes. It also enables similar classes to share properties through "inheritance"
below. A hierarchy is useful if there are several classes which are fundamentally
4


similar to each other. In C++, a "base class" is a synonym for superclass and
"derived class" is a synonym for subclass.

                                                    Object

                                              ...

                                    Animal              ...


                             Bird                    ...


                      Duck                   ...

Inheritance
"Inheritance" is the process by which a class inherits the properties of its
superclasses. Methods in particular are inherited. When an object receives a
message, it checks for a corresponding method in its class. If one is found, it is
executed. Otherwise the search for a matching method travels up the tree to the
superclass of the object's class. This means that a class automatically responds to
all the messages of its superclasses. Most OOP languages include controls to limit
which properties are inherited.

Overriding
When an object receives a message, it checks its own methods first before
consulting its superclass. This means that if the object's class and its superclass
both contain a method for a message, the object's method takes precedence. In
other words, the first method found in the hierarchy takes precedence. This is
known as "overriding," because it gives a class an easy way to intercept messages
before they get to its superclass. Most OOP languages implement overriding
based on the run-time class of objects. In C++, run-time overriding is an option
invoked with the "virtual" keyword.

Polymorphism
A big word for a simple concept. Often, many classes in a program will respond
to some common message. In a graphics program, many of the classes are likely
to implement the method "DrawSelf()." In the program, such an object can safely
be sent the DrawSelf() message without knowing its exact class since all the
classes implement or inherit DrawSelf(). In other words, you can send the object
a message without worrying about its class and be confident that it will just do
the right thing. Polymorphism is important when the code is complex enough
that you are no longer sure of the exact class of an object — you can just send it a
message and rely on it doing the right thing at run time based on its class.

More Related Content

What's hot (20)

PDF
Object oriented programming
mustafa sarac
 
PPTX
General oops concepts
nidhiyagnik123
 
PPT
Java Notes
Abhishek Khune
 
PDF
Xml representation oftextspecifications
usert098
 
PPT
Object-oriented concepts
BG Java EE Course
 
PDF
SOLID Deconstruction
Kevlin Henney
 
PPT
Java Basics
shivamgarg_nitj
 
PPT
What is OOP?
Amin Uddin
 
PPT
Md03 - part3
Rakesh Madugula
 
PPT
Unit 1 Java
arnold 7490
 
PPT
JAVA BASICS
VEERA RAGAVAN
 
DOC
My c++
snathick
 
PPT
Static and Dynamic polymorphism in C++
Anil Bapat
 
PPTX
The Go Programing Language 1
İbrahim Kürce
 
PDF
Pocket java
Kumaran K
 
DOC
Core java questions
Dinesh Reddy G
 
PPT
Oops Concepts
guest1aac43
 
DOCX
Java se 8 fundamentals
megharajk
 
PPTX
Object oriented programming concepts
rahuld115
 
PDF
Oop
志明 陳
 
Object oriented programming
mustafa sarac
 
General oops concepts
nidhiyagnik123
 
Java Notes
Abhishek Khune
 
Xml representation oftextspecifications
usert098
 
Object-oriented concepts
BG Java EE Course
 
SOLID Deconstruction
Kevlin Henney
 
Java Basics
shivamgarg_nitj
 
What is OOP?
Amin Uddin
 
Md03 - part3
Rakesh Madugula
 
Unit 1 Java
arnold 7490
 
JAVA BASICS
VEERA RAGAVAN
 
My c++
snathick
 
Static and Dynamic polymorphism in C++
Anil Bapat
 
The Go Programing Language 1
İbrahim Kürce
 
Pocket java
Kumaran K
 
Core java questions
Dinesh Reddy G
 
Oops Concepts
guest1aac43
 
Java se 8 fundamentals
megharajk
 
Object oriented programming concepts
rahuld115
 

Viewers also liked (10)

PDF
Boolean algebra
Swarup Kumar Boro
 
PDF
Arrays and library functions
Swarup Kumar Boro
 
DOCX
Physics
Swarup Kumar Boro
 
PDF
computer science sample papers 1
Swarup Kumar Boro
 
PDF
computer science sample papers 2
Swarup Kumar Boro
 
PDF
Boolean algebra laws
Swarup Kumar Boro
 
PDF
computer science sample papers 3
Swarup Kumar Boro
 
TXT
c++ program for Railway reservation
Swarup Kumar Boro
 
PDF
Structures in c++
Swarup Kumar Boro
 
Boolean algebra
Swarup Kumar Boro
 
Arrays and library functions
Swarup Kumar Boro
 
computer science sample papers 1
Swarup Kumar Boro
 
computer science sample papers 2
Swarup Kumar Boro
 
Boolean algebra laws
Swarup Kumar Boro
 
computer science sample papers 3
Swarup Kumar Boro
 
c++ program for Railway reservation
Swarup Kumar Boro
 
Structures in c++
Swarup Kumar Boro
 
Ad

Similar to Oop basic concepts (20)

PPT
Oop by edgar lagman jr
Jun-jun Lagman
 
PDF
com-213-unified-modelling-launguage-programming-theory.pdf
AhmadInternetCafe
 
PPT
73d32 session1 c++
Mukund Trivedi
 
PPT
C plusplus
Niti Bansal
 
PPT
General OOP concept [by-Digvijay]
Digvijay Singh Karakoti
 
DOC
Chapter1
jammiashok123
 
PDF
Ruby — An introduction
Gonçalo Silva
 
PPTX
Object oriented programming 6 oop with c++
Vaibhav Khanna
 
DOCX
Java OOPs Concepts.docx
FredWauyo
 
DOCX
Mcs024
vicky sharma
 
PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
PDF
C++ programing lanuage
Nimai Chand Das
 
PPT
Week1
Uzma Qureshi
 
PPT
Csci360 20 (1)
manish katara
 
PPT
Csci360 20
neetukalra
 
PPTX
Object oriented programming concept
Pina Parmar
 
PDF
OOP concepts with respected with Python
pankajdesai217634
 
PPT
Lecture 2
emailharmeet
 
Oop by edgar lagman jr
Jun-jun Lagman
 
com-213-unified-modelling-launguage-programming-theory.pdf
AhmadInternetCafe
 
73d32 session1 c++
Mukund Trivedi
 
C plusplus
Niti Bansal
 
General OOP concept [by-Digvijay]
Digvijay Singh Karakoti
 
Chapter1
jammiashok123
 
Ruby — An introduction
Gonçalo Silva
 
Object oriented programming 6 oop with c++
Vaibhav Khanna
 
Java OOPs Concepts.docx
FredWauyo
 
Mcs024
vicky sharma
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
C++ programing lanuage
Nimai Chand Das
 
Csci360 20 (1)
manish katara
 
Csci360 20
neetukalra
 
Object oriented programming concept
Pina Parmar
 
OOP concepts with respected with Python
pankajdesai217634
 
Lecture 2
emailharmeet
 
Ad

More from Swarup Kumar Boro (16)

TXT
c++ program for Canteen management
Swarup Kumar Boro
 
PDF
Pointers
Swarup Kumar Boro
 
PDF
File handling
Swarup Kumar Boro
 
PDF
Constructor & destructor
Swarup Kumar Boro
 
PDF
Functions
Swarup Kumar Boro
 
PDF
Implementation of oop concept in c++
Swarup Kumar Boro
 
PDF
2-D array
Swarup Kumar Boro
 
PDF
C++ revision tour
Swarup Kumar Boro
 
PDF
Computer science study material
Swarup Kumar Boro
 
PDF
01 computer communication and networks v
Swarup Kumar Boro
 
PDF
1-D array
Swarup Kumar Boro
 
PDF
Function overloading
Swarup Kumar Boro
 
PPTX
Physics activity
Swarup Kumar Boro
 
c++ program for Canteen management
Swarup Kumar Boro
 
File handling
Swarup Kumar Boro
 
Constructor & destructor
Swarup Kumar Boro
 
Implementation of oop concept in c++
Swarup Kumar Boro
 
C++ revision tour
Swarup Kumar Boro
 
Computer science study material
Swarup Kumar Boro
 
01 computer communication and networks v
Swarup Kumar Boro
 
Function overloading
Swarup Kumar Boro
 
Physics activity
Swarup Kumar Boro
 

Recently uploaded (20)

PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPT
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Introduction presentation of the patentbutler tool
MIPLM
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Difference between write and update in odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 

Oop basic concepts

  • 1. Cs193i, Stanford Handout #28 Spring, 99-00 Nick Parlante OOP Concepts (This is a CS108 handout on the basics terminology and structures of OOP.) Object Oriented Programming, OOP, is the must influential paradigm of our time. This handout summarizes the very basic style, elements, and vocabulary of OOP that are common to all OOP languages. OOP languages can have their obscure features, but the basic ideas of OOP are pretty straightforward. Pre-OOP In a classical compiled language like Pascal or C, data-structures and their operations are arranged logically, but it is the programmer's duty to devise and enforce these arrangements. Related functions tend to go in one file, but the basic operation of matching of the right operation with the right type of variable remains a programmer chore. In the best case, is mismatch will result in a compile time error. In the worst case, such as with a mis-cast void*, a mismatch will crash in some unpleasant way. OOP In OOP, the logical arrangement of the code is changed. Instead of an informal arrangement of functions into different files, functionality is officially and tightly grouped with the type that it operates on. The OOP style groups all the operations together according to what they operate on — all the hash table operations are part of the hash table class, all the string operations are part of the string class. Put another way: if variables are nouns and functions are verbs, then OOP divides up everything in to categories based on the noun. Historically, there are many ways to structure code, but the OOP style has proved to work quite well. OOP yields a pretty obvious decomposition and facilitates code re-use. Most importantly, OOP keeps the role of client and implementor separate. Keeping the client side separate from the implementation side has a host of advantages. Don't just think "oh yeah, client separate from implementor — too basic for me." It's not sexy, but it's useful. OOP formalizes and enforces the separation. It no longer requires any special skill to keep them separate; the language makes it the most convenient way to proceed. The strengths of OOP help the most when writing large programs, programming in teams, and perhaps most importantly, packaging up code into libraries for use by others. The Grail of Code Re-Use One of the obvious goals of language design has been to make it possible, finally, to stop re-creating common code for every project. Lists, hash-tables, windows, buttons ... these are things that should not have to be re-created for every project. For code re-use to really work, it must be easy to be a client of that code. OOP, and Java and its libraries in particular, appear to be our best hope of finally obtaining true code re-use.
  • 2. 2 The Clueless Client Test The "clueless client test: a language has good support for code re-use if it is possible to build a library of code, give it to a client who wants that behavior, and that client can get the behavior from the library even if the client is clueless or a little clumsy. The language should encourage the right client behavior and discourage common client errors and politely alert the client if there is an error. The DArray in C, for example, fails the clueless client test: the client needs to use it exactly right, or it blows up in their face. Class The most basic concept in OOP is the Class. A class is like a type in classical language. Instead of just storing size and structural information for its data, a class also stores the operations which will apply to the data. Class = Storage + Behavior. A class is like an Abstract Data Type in Pascal or C— it creates a logical coupling between data and the operations on that data. Bundle the verbs with their nouns. Object An object is a run-time value that stores state and belongs to some class. So if classes are like types, then objects are like variables. Where plain old variables just have a type, objects belong to a class, and so they automatically know what operations they are capable of. The word "instance" is a synonym for "object." The phrase "an instance of the string class" to identify an run time object of the string class sounds better than "an object of the string class." Message and Method OOP uses "messages" instead of function calls. Sending a message to an object causes that object to perform an operation on itself. In that case, the object receiving the message and performing the operation is known as the "receiver". The receiver looks at the message, figures out the appropriate operation to perform, and executes that operation on itself. The receiver knows what operations it can perform, because it knows its class, and the class defines all the operations for its instances. The code corresponding to a particular message is known as the "method" for that message. A message is just a string like "Pop()". The method for Pop() is the code in the Stack class which is triggered by the "Pop()" message. The C++ specific term for method is "member function". // Traditional programming // Call the Foo() operation, and pass it the data to operate on Foo(x); // OOP programming // Send a "Foo()" message to the object -- the "receiver" of the message. // The receiver gets the message, finds the matching method code in its class, // and the method code executes on the receiver. x ← "Foo()" The method that executes depends on the class of the receiver. If you send the Print() message to a Stack object, you get the Print() method in the Stack class. If
  • 3. 3 you send that same Print() message to a HashTable object, you get the (different) Print() method in the HashTable class. It's what you say, and the class of the receiver that you say it to. Message Send Syntax In Java and C++, the syntax for sending a message looks like appending the message to the desired receiver with a dog: x.Foo(); // Send the "Foo()" message to the receiver "x" Receiver Relative Code We say that "the method executes against the receiver." This just means that the method code operates on the data of the receiver. So in code like the following... x ← "RemoveAllElements" y ← "AddElement(12)" The receiver x is, apparently, going to remove all the elements it is storing, while the receiver y is adding an element. The method operates on the receiver it is sent to — x or y in this case. This makes methods different from plain C functions. C functions operate on the parameters they are passed. Methods, on the other hand, always have a receiver object to operate on. Parameters are only necessary for extra data. Encapsulation "Encapsulation" refers to protecting the internals of an object from direct manipulation by the client. The client can send messages, but the client cannot change the bits in the object directly. In C , it's just a convention that the client should not mess with or depend on the implementation of an Abstract Data Type (ADT). With encapsulation, the compiler enforces the separation. The class implementation can indicate which parts of the implementation are protected so that client code accessing those parts will not compile. Or put another way: the client cannot mess with the object's state — the client can only send messages. The object's state is only touched by its own methods. Once those methods are correct and debugged, the object can be given to any client, and that client should not be able to perform an operation on the object which puts it in an incorrect state. This depends on the methods being correct which is still difficult. But when they are correct at last, the client should not be able to mess things up. Hierarchy Classes in OOP are arranged in a tree-like hierarchy. A class' "superclass" is the class above it in the tree. The classes below a class are its "subclasses." The semantics of the hierarchy are that classes have all the properties of their superclasses. In this way the hierarchy is general up towards the root and specific down towards its leaves. The hierarchy helps add logic to a collection of classes. It also enables similar classes to share properties through "inheritance" below. A hierarchy is useful if there are several classes which are fundamentally
  • 4. 4 similar to each other. In C++, a "base class" is a synonym for superclass and "derived class" is a synonym for subclass. Object ... Animal ... Bird ... Duck ... Inheritance "Inheritance" is the process by which a class inherits the properties of its superclasses. Methods in particular are inherited. When an object receives a message, it checks for a corresponding method in its class. If one is found, it is executed. Otherwise the search for a matching method travels up the tree to the superclass of the object's class. This means that a class automatically responds to all the messages of its superclasses. Most OOP languages include controls to limit which properties are inherited. Overriding When an object receives a message, it checks its own methods first before consulting its superclass. This means that if the object's class and its superclass both contain a method for a message, the object's method takes precedence. In other words, the first method found in the hierarchy takes precedence. This is known as "overriding," because it gives a class an easy way to intercept messages before they get to its superclass. Most OOP languages implement overriding based on the run-time class of objects. In C++, run-time overriding is an option invoked with the "virtual" keyword. Polymorphism A big word for a simple concept. Often, many classes in a program will respond to some common message. In a graphics program, many of the classes are likely to implement the method "DrawSelf()." In the program, such an object can safely be sent the DrawSelf() message without knowing its exact class since all the classes implement or inherit DrawSelf(). In other words, you can send the object a message without worrying about its class and be confident that it will just do the right thing. Polymorphism is important when the code is complex enough that you are no longer sure of the exact class of an object — you can just send it a message and rely on it doing the right thing at run time based on its class.