



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of inheritance and polymorphism in object-oriented programming (oop), as presented in l. Dillon's cse 452 course during the fall 2008 semester. The execution of a call in c, dynamic binding, and modelling single and multiple inheritance. It also discusses the need for a 'view' of each parent in an heir and the adaptation of parents in an inheritance hierarchy.
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




L. Dillon, CSE 452, Fall 2008
1
L. Dillon, CSE 452, Fall 2008
L. Dillon, CSE 452, Fall 2008
3
L. Dillon, CSE 452, Fall 2008
L. Dillon, CSE 452, Fall 2008
5
L. Dillon, CSE 452, Fall 2008
INT field
L. Dillon, CSE 452, Fall 2008
7
INT field
INT fieldINT field
L. Dillon, CSE 452, Fall 2008 class
create
set
feature
a: INTEGER
set(n:
is
do
a := n end
f(n:
like
Current
is
do
create
Result.set(n
a) end
get_a
is
do
Result
a end
end
class
inherit
redefine
set
end
create
set
feature
b: INTEGER
set(n:
is
do
a := n; b := n end
get_b:
is
do
Result
b end
end
class
create
make
feature
make
is
local
a: A
b1,
b2:
B
do
create
b1.set(1)
a :=
b1.f
b ?=
a
end
end
L. Dillon, CSE 452, Fall 2008
13
a
b
c
f
ctp: g a:
ctp: b:
g:^ B’s table f: A’s table
B’s gcode forA’s f code for
h
C-as-A table h: f:
C-as-B table g:
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
C’s h code for
x:
...
Fx.g: (^) push
(^) x (^) onto stack (for callee’s
(^) Current
(^) push return address & jump to code for
(^) g (^) (found at
(^) ((x+
Code for
’s (^) g (^) expects:
b (^) at (^) Current+
code for
(^) g (^) at
**Current
size 4) (assuming ptrs & ints of
L. Dillon, CSE 452, Fall 2008
a
b
c
f
ctp: g a:
ctp: b:
g: B’s table f: A’s table
B’s gcode forA’s f code for
h
C-as-A table h: f:
C-as-B table g:
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
C’s h code for
x:
...
F x.g: push
(^) x+
(^) onto stack (for callee’s
(^) Current
push return address & jump to code for
(^) g (^) (found at
(^) ((x+
Code for
’s (^) g (^) expects:
(^) b (^) at (^) Current+
(^) code for
(^) g (^) at
**Current
size 4) (assuming ptrs & ints of
L. Dillon, CSE 452, Fall 2008
15
a
b
c
f
ctp: g a:
ctp: b:
g:^ B’s table f: A’s table
B’s gcode forA’s f code for
h
C-as-A table h: f:
C-as-B table g:
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
C’s h code for
x:
...
y := x :
(^) “normal” assignment
y:
...
L. Dillon, CSE 452, Fall 2008
a
b
c
f
ctp: g a:
ctp: b:
g: B’s table f: A’s table
B’s gcode forA’s f code for
h
C-as-A table h: f:
C-as-B table g:
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
C’s h code for
x:
...
z := x :
store
x+
(^) into location bound to
(^) z
z:
...
a
b
c
f
hg
redefine
h
rename
f as
k
ctp: a:
ctp: b:
h: g: B’s table f: A’s table
B’s hcode forB’s gcode forA’s f code for
a
b
c
f
hg
redefine
h
rename
f as k
ctp: a:
ctp: b:
h: g: B’s table f: A’s table
B’s hcode forB’s gcode forA’s f code for
h: 8 g: 0 C-as-B table h: 0 k: 0 C-as-A table
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
x:
...
C’s h code for
a
b
c
f
hg
redefine
h
rename
f as
k
ctp: a:
ctp: b:
h: g: B’s table f: A’s table
B’s hcode forB’s gcode forA’s f code for
h: 8 g: 0 C-as-B table h: 0 k: 0 C-as-A table
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
x:
...
C’s h code for
F x.k: (^) push
(^) x (^) onto stack (for callee’s
(^) Current
(^) push return address & jump to code for
(^) k (^) (code for A’s f, found at
(x)
obvious amounts.)address calculation by theconstants used in thepresence affects thebe explained later; theirthese “displacements” willing slides; the purpose ofhere and in the remain-address calculationsthe tables in theignoring the numbers in (For simplicity, I am
a
b
c
f
hg
redefine
h
rename
f as k
ctp: a:
ctp: b:
h: g: B’s table f: A’s table
B’s hcode forB’s gcode forA’s f code for
h: 8 g: 0 C-as-B table h: 0 k: 0 C-as-A table
B’s gcode forA’s f code for
ctp: a:
ctp: c:b:
x:
...
C’s h code for
y:
...
F y.f: push
(^) y (^) onto stack (for callee’s
(^) Current
push return address & jump to code for
(^) f (^) (found at
(^) (y)
y := x
(^) “normal” assignment
L. Dillon, CSE 452, Fall 2008
25
class
feature a: INTEGER
set(n:
is
do
a :=
n end
f(n:
like
Current
is
do
create
Result
Result.set(n
a)
end
get
is
do
Result
a end
end
class
feature b: INTEGER
set(n:
is
do
b := n end
get:
is
do
Result
b end
end
class
inherit
rename set
as
set1,
get
as
get
end
rename set
as
set
redefine
get
end
feature c:
INTEGER
get
is
do
Result
c
b end
g is
do c := a
b end
end
class
create
make
feature make
is
local a: A; b: B;
c:C
do
create
c
c.set1(1);
c.set2(2);
c.g
a := c; b:=
c;
end
end
L. Dillon, CSE 452, Fall 2008