Computer Programming
Object Oriented Programming:
Its Origins and Importance in
Computer Science
?
Prof. Jeffrey S. Rosenschein
School of Computer Science and Engineering
Hebrew University, Jerusalem, Israel
The history of computer
programming is a steady move
away from machine-oriented
views of programming towards
concepts and metaphors that
more closely reflect the way in
which we ourselves understand
the world
2
Programming progression…
?
Machine language – Mark I
Programming has progressed through:
?
?
?
?
?
machine code
assembly language
machine-independent programming
languages
procedures & functions
objects
3
Machine Language
4
Assembly Language – PDP-11
0000 1001 1100 0110 1010 1111 0101 1000
1010 1111 0101 1000 0000 1001 1100 0110
1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
5
6
1
Assembly Language – Macro-11
GCD:
SIMPLE:
TST
BEQ
MOV
SXT
DIV
MOV
MOV
CALL
RETURN
Assembly Language – Macro-11
B
SIMPLE
A, R5
R4
B, R4
B, A
R5, B
GCD
GCD:
SIMPLE:
TST
BEQ
MOV
SXT
DIV
MOV
MOV
CALL
RETURN
B
SIMPLE
A, R5
R4
B, R4
B, A
R5, B
GCD
20
20/
7
Machine-Independent Programming Languages
– Fortran
8
Procedures & Functions – Pascal
! This example program solves for roots of the quadratic equation,
! ax^2 +bx +c =0,for given values of a, b and c.
!
PROGRAM bisection
IMPLICIT NONE
INTEGER :: iteration
DOUBLE PRECISION :: CC, Er, xl, x0, x0_old, xr
program ValueArg(output );
{Shows how to arrange for a procedure to have arguments.}
procedure PrintInitials(First, Last : char);
{Within this procedure, the names First and Last represent the
argument values. We’ll call write to print them.}
begin
write(‘ My initials are: ’);
write(First);
writeln(Last)
end; {PrintInitials}
! Set convergence criterion and guess for xl, xr.
CC = 1.d -4
xl = 8.d -1
xr = 11.d -1
! Bisection method.
Er =CC +1
iteration = 0
DO WHILE ( Er > CC)
iteration = iteration + 1
! Compute x0 and the error.
x0_old = x0
x0 = (xl + xr) / 2.d0
Er = DABS((x0 - x0_old)/x0)*100.d0
WRITE (*,10) iteration, x0_old, x0, Er
10 FORMAT (1X,I4,3(2X,E10.4))
begin
PrintInitials (‘D’, ‘C’); {Any two characters can be arguments.}
PrintInitials (‘Q’, ‘T ’); {Like strings, characters are quoted.}
PrintInitials (‘&’, ‘#’)
end. {ValueArg}
this is partial…
9
Objects
?
10
“Intrinsic Power” vs. “Effective Power”
?
(My examples will be from Java)
?
class Time {
private int hour, minute;
public Time (int h, int m) {
hour = h;
minute = m;
}
?
public void addMinutes (int m) {
int totalMinutes =
((60*hour) + minute + m) % (24*60);
if (totalMinutes<0)
totalMinutes = totalMinutes + (24*60);
hour = totalMinutes / 60;
minute = totalMinutes % 60;
}
This progression is not a matter of “intrinsic power”
Anything you can do with a minimally capable
computer language, you can theoretically do with
any other minimally capable computer language
But that is like saying a shovel is theoretically as
capable as a tractor. In practice, using a shovel
might make things very hard …
}
this is partial…
11
12
2
Objects
Classes and Objects
class
Time
hour
minute
void addMinutes( int m )
inTime
Attributes:
hour = 8
minute = 30
Methods:
void addMinutes(int m)
outTime
Attributes:
hour = 17
minute = 35
Methods:
void addMinutes(int m)
objects
?
A class is a prototype for creating
objects
?
When we write a program in an
object-oriented language like Java,
we define classes, which in turn are
used to create objects
?
A class has a constructor for
creating objects
13
A Simple Class, called “Time” (partial)
Definition of an “Object”
class Time {
private int hour, minute;
14
constructor for Time
An object is a computational entity that:
?
1.
public Time (int h, int m) {
hour = h;
minute = m;
}
2.
public void addMinutes (int m) {
int totalMinutes =
((60*hour) + minute + m) % (24*60);
if (totalMinutes<0)
totalMinutes = totalMinutes + (24*60);
hour = totalMinutes / 60;
minute = totalMinutes % 60;
}
3.
Encapsulates some state
Is able to perform actions, or methods, on this
state
Communicates with other objects via message
passing
}
15
1) Encapsulates some state
?
?
16
Pascal Example: Represent a Time
Like a record in Pascal, it has a set of
variables (of possibly different types)
that describe an object’s state
These variables are sometimes called
an object’s attributes (or fields, or
instance variables, or datamembers,
or …)
type TimeTYPE = record
Hour: 1..23;
Minute: 0..59;
end;
var inToWork, outFromWork: TimeTYPE;
17
18
3
Java Example: Represent a Time
Objects
attributes of Time
class Time {
class
private int hour, minute;
Time
inToWork
hour
minute
public Time ( int h, int m) {
hour = h;
minute = m;
}
void addMinutes( int m )
…
Attributes:
hour = 8
minute = 30
Methods:
void addMinutes(int m)
outFromWork
constructor for Time
}
Attributes:
hour = 17
minute = 35
Methods:
void addMinutes(int m)
Time inToWork = new Time(8, 30);
Time outFromWork = new Time(17, 35);
objects
19
2) Is able to perform actions, or methods,
on this state
?
?
20
3) Communicates with other objects via
message passing
More than a Pascal record!
An object can also include a group of procedures/functions
that carry out actions
?
Sends messages to objects, triggering
methods in those objects
class Time {
private int hour, minute;
public Time (int h, int m) {
hour = h;
minute = m;
}
a method of Time
void
public void addMinutes (int m) {
int totalMinutes =
((60*hour) + minute + m) % (24*60);
if (totalMinutes<0)
totalMinutes = totalMinutes + (24*60);
hour = totalMinutes / 60;
minute = totalMinutes % 60;
}
}
21
Example of Object Creation
and Message Passing
22
Example of Object Creation
and Message Passing
In one of bill’ s methods, the following code appears:
Time inToWork = new Time(8, 30);
inToWork.addMinutes(15);
bill
Attributes:
…
Methods:
…
bill
Attributes:
…
Methods:
…
23
24
4
Example of Object Creation
and Message Passing
Example of Object Creation
and Message Passing
In one of bill’ s methods, the following code appears:
Time inToWork = new Time(8, 30);
inToWork.addMinutes(15);
In one of bill’ s methods, the following code appears:
Time inToWork = new Time(8, 30);
inToWork.addMinutes(15);
inToWork
Attributes:
hour = 8
minute = 30
Methods:
void addMinutes(int m)
inToWork.addMinutes(15)
bill
Attributes:
…
Methods:
…
inToWork
Attributes:
hour = 8
minute = 30
Methods:
void addMinutes(int m)
bill
Attributes:
…
Methods:
…
25
Example of Object Creation
and Message Passing
26
Structure of a Class Definition
class name {
In one of bill’ s methods, the following code appears:
Time inToWork = new Time(8, 30);
inToWork.addMinutes(15);
inToWork
Attributes:
hour = 8
minute = 45
Methods:
void addMinutes(int m)
bill
Attributes:
…
Methods:
…
declarations
attributes and
symbolic constants
constructor definition(s)
how to create and
initialize objects
method definitions
how to manipulate
the state of objects
}
These parts of a class can
actually be in any order
27
History of Object-Oriented Programming
?
?
The Ideas Spread
Started out for simulation of complex manmachine systems, but was soon realized that
it was suitable for all complex programming
projects
SIMULA I (1962-65) and Simula 67 (1967)
were the first two object-oriented languages
?
?
28
Developed at the Norwegian Computing Center,
Oslo, Norway by Ole-Johan Dahl and Kristen
Nygaard
Simula 67 introduced most of the key concepts of
object-oriented programming: objects and classes,
subclasses (“inheritance”), virtual procedures
29
?
Alan Kay, Adele Goldberg and colleagues at
Xerox PARC extend the ideas of Simula in
developing Smalltalk (1970’s)
?
?
?
?
?
Kay coins the term “object oriented”
Smalltalk is first fully object oriented language
Grasps that this is a new programming paradigm
Integration of graphical user interfaces and
interactive program execution
Bjarne Stroustrup develops C++ (1980’s)
?
Brings object oriented concepts into the C
programming language
30
5
Other Object Oriented Languages
?
?
?
?
?
?
?
REVIEW: Definition of an “Object”
Eiffel (B. Meyer)
CLOS (D. Bobrow, G. Kiczales )
SELF (D. Ungar et al.)
Java (J. Gosling et al.)
BETA (B. Bruun-Kristensen, O. Lehrmann
Madsen, B. Møller-Pedersen, K. Nygaard)
Other languages add object dialects, such as
TurboPascal
…
?
An object is a computational entity that:
?
?
?
Encapsulates some state
Is able to perform actions, or methods, on this
state
Communicates with other objects via message
passing
31
Encapsulation
?
?
?
?
32
Advantages
The main point is that by thinking of the
system as composed of independent objects,
we keep sub-parts really independent
They communicate only through well-defined
message passing
Different groups of programmers can work on
different parts of the project, just making sure
they comply with an interface
It is possible to build larger systems with less
effort
Building the system as a group of interacting
objects:
? Allows extreme modularity between
pieces of the system
? May better match the way we (humans)
think about the problem
? Avoids recoding, increases code-reuse
33
But there’s more…
34
Example of Class Inheritance
Object
?
?
?
?
Classes can be arranged in a hierarchy
Subclasses inherit attributes and
methods from their parent classes
This allows us to organize classes, and
to avoid rewriting code – new classes
extend old classes, with little extra work!
Allows for large, structured definitions
toString ( )
equals( Object obj )
getClass( )
Objects made from this
class, for example, have
all the attributes and
methods of the classes
above them, all the way
up the tree
extends
Rectangle
length
width
int computeArea( )
35
Shape
extends
color
borderWidth
Color getColor( )
void setBorderWidth( int m )
extends
Circle
radius
int computeArea( )
extends
Time
hour
minute
void addMinutes( int m )
extends
Triangle
base
height
int computeArea( )
36
6
Java Class Hierarchy
Java Class Hierarchy, another view
37
Polymorphism
?
?
38
Polymorphism
An object has “multiple identities ”, based on
its class inheritance tree
It can be used in different ways
?
?
?
An object has “multiple identities ”, based on
its class inheritance tree
It can be used in different ways
A Circle is-a Shape is-a Object
Object
toString( )
equals( Object o b j )
getClass( )
extends
Shape
color
borderWidth
Color getColor ( )
void setBorderWidth ( i n t m )
extends
Circle
radius
int computeArea ( )
39
Polymorphism
?
?
?
40
How Objects are Created
An object has “multiple identities ”, based on
its class inheritance tree
It can be used in different ways
A Circle is-a Shape is-a Object
Circle c = new Circle( );
Object
toString( )
equals( Object o b j )
getClass( )
extends
Shape
color
borderWidth
Color getColor ( )
void setBorderWidth ( i n t m )
extends
Circle
radius
Object
Shape
Circle
A Circle object really has 3 parts
int computeArea ( )
41
42
7
How Objects are Created
How Objects are Created
Circle c = new Circle( );
Circle c = new Circle( );
1.
1.
c
1.
1.
2.
2.
Object
Object
Object
Shape
Shape
Shape
Circle
Circle
c
c
Execution Time
Circle
Execution Time
43
How Objects are Created
44
Three Common Uses for Polymorphism
Circle c = new Circle( );
1.
1.
2.
2.
1.
3.
3.
Object
Object
Object
Shape
Shape
Shape
2.
3.
c
Circle
Circle
c
c
Circle
Using Polymorphism in Arrays
Using Polymorphism for Method
Arguments
Using Polymorphism for Method
Return Type
Execution Time
45
46
1) Using Polymorphism in Arrays
?
1) Using Polymorphism in Arrays
We can declare an array to be filled with “Shape”
objects, then put in Rectangles, Circles, or
Triangles
Object
?
We can declare an array to be filled with “Shape”
objects, then put in Rectangles, Circles, or
Triangles
toString( )
equals( Object obj)
getClass( )
extends
Shape
samples
color
borderWidth
(an array
of Shape
objects)
Color getColor ( )
void setBorderWidth( int m )
extends
Rectangle
length
width
int computeArea ( )
extends
Circle
radius
int computeArea ( )
extends
Triangle
base
height
int computeArea( )
[0]
47
[1]
[2]
48
8
1) Using Polymorphism in Arrays
?
1) Using Polymorphism in Arrays
We can declare an array to be filled with “Shape”
objects, then put in Rectangles, Circles, or
Triangles
firstShape
samples
(an array
of Shape
objects)
secondShape
Attributes:
Attributes:
length
[2]= 17
radius = 11
width = 35
Methods:
Methods:
int computeArea( )
int computeArea( )
[0]
?
We can declare an array to be filled with “Shape”
objects, then put in Rectangles, Circles, or
Triangles
thirdShape
firstShape
Attributes:
base = 15
height = 7
Methods:
int computeArea( )
[1]
samples
(an array
of Shape
objects)
[2]
secondShape
Attributes:
Attributes:
length
[2]= 17
radius = 11
width = 35
Methods:
Methods:
int computeArea( )
int computeArea( )
thirdShape
le
tang
Rec
le
Circ
Attributes:
base = 15
height = 7
Methods:
int computeArea( )
[0]
[1]
[2]
ngle
Tria
49
50
2) Using Polymorphism for Method
Arguments
?
2) Using Polymorphism for Method
Arguments
We can create a procedure that has Shape as
the type of its argument, then use it for objects
of type Rectangle, Circle, and Triangle
public int calculatePaint (Shape myFigure ) {
?
public int calculatePaint (Shape myFigure ) {
final int PRICE = 5;
final int PRICE = 5;
int totalCost = PRICE * myFigure.computeArea( );
return totalCost ;
}
int totalCost = PRICE * myFigure.computeArea( );
return totalCost ;
}
The actual definition of computeArea( ) is known only at
runtime, not compile time – this is “ dynamic binding”
?
To do this, we need to declare in Shape’s class definition
that its subclasses will define the method computeArea ( )
51
3) Using Polymorphism for Method
Return Type
52
Java Convinced Me to Start Teaching
Object-Oriented in Intro to CS
We can write general code, leaving the type
of object to be decided at runtime
?
?
public Shape createPicture ( ) {
/* Read in choice from user */
System.out.println(“1 for rectangle, ” +
“2 for circle, 3 for triangle: ”);
SimpleInput sp = new SimpleInput(System.in);
int i = sp.readInt ( );
?
?
?
?
if ( i == 1 ) return new Rectangle(17, 35);
if ( i == 2 ) return new Circle(11);
if ( i == 3 ) return new Triangle(15, 7);
}
Polymorphism give us a powerful way of
writing code that can handle multiple types
of objects, in a unified way
53
Java is Object-Oriented from the Ground Up
Java has the elegance that comes from being
designed after other OO languages had been in use
for many years
Java has strong type checking
Java handles its own memory allocation
Java’s syntax is “standard ” (similar to C and C++)
Java is a good teaching language, but it (or
something close) will also be seen by students in
industry
54
9
Object-Oriented Programming in Industry
Conclusions
?
?
?
?
Large projects are routinely programmed
using object-oriented languages
nowadays
MS-Windows and applications in MSOffice – all developed using objectoriented languages
This is the world into which our students
are graduating…
?
55
Object-oriented programming provides a superior
way of organizing programming projects
?
It encourages a high degree of modularity in
programming, making large projects easier to
implement
?
It provides powerful techniques like inheritance and
polymorphism to help organize and reuse code
Object-oriented languages like Java both provide
a good environment for beginning students to
learn programming, and match real-world
developments in computer programming
56
10
© Copyright 2026 Paperzz