Objectives - PowerPoint PPT Presentation

About This Presentation
Title:

Objectives

Description:

... apply m1 c3 o3_rep (7 8)) (new-object c3) Object Representation (o3) ... Class Representation (c3) Flatten Class Fields 5.4.3. Object Representation (o3) a-part ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 10
Provided by: jeffrey105
Learn more at: http://www.cs.rpi.edu
Category:
Tags: c3 | objectives

less

Transcript and Presenter's Notes

Title: Objectives


1
Objectives
  • Understand grammar of OOP
  • Understand equivalent Java code
  • Discuss different implementations of classes and
    objects

2
Class Declarations
ltprogramgt ltclass-declgt ltexpressiongt
a-program (class-decls body)
ltclass-declgt class ltidentifiergt extends ltidentifiergt field ltidentifiergt ltmethod-declgt
a-class-decl (class-name super-name field-ids method-decls)
ltmethod-declgt method ltidentifiergt (ltidentifiergt(,)) ltexpressiongt
a-method-decl (method-name ids body)
3
Object Expressions
ltexpressiongt new ltidentifiergt (ltexpressiongt(,)) ltexpressiongt
new-object-exp (class-name rands)
ltexpressiongt send ltexpressiongt ltidentifiergt (ltexpressiongt(,))
method-app-exp (obj-exp method-name rands)
ltexpressiongt super ltidentifiergt (ltexpressiongt(,))
super-call-exp (method-name rands)
4
How do we do this in Java?
class c2 extends c1 Public class c2 extends c1
field x Public int x
method initialize() set x 1 Public c2() x 1
method m1 (a) (x, a) Public int m1(int a) return xa
method m2 (c) send self m1 ((c, 4)) Public int m2(int c) return m1(c4)
method m3 (a, b) super m1 (a, b) Public int m3(int a, int b) return super.m1(a,b)
let o1 new c2() in Public static void main (String args) c2 o1 new c2()
send o1 m2 (3) o1.m2(3)
5
How do we implement this?
  • idea

Class Declarations
store class definitions
Class Representation
Method Bodies
Object Representation
access classes and objects when executing
program
Program Body
Base code is in 5-3.scm
Implementation code is in 5-4-x.scm
6
Interface to Classes
Class Declarations
elaborate-class-decls! (build repository of
classes)
Class Representation
Method Bodies
object-gtclass-name (what kind of object am I?)
super send new
Object Representation
find-method-and-apply (perform send)
Program Body
new-object (allocate new object)
7
Simple Implementation 5.4.1
object is list of class-name / fields parts
directly from grammar
How do we implement (elaborate-class-decls!
c-decls) (object-gtclass-name o3_rep) (find-method-
and-apply m1 c3 o3_rep (7 8)) (new-object c3)
8
Flatten Object Fields 5.4.2
directly from grammar
Object Representation (o3)
Class Representation (c3)
a-part
a-class-decl
c3
class-name
c3
class-name
fields
search from right
super-name
c2
field-ids
z
x
32
31
22
12
11
method-decls
x
z
y
x
y
c1
c3
c2
v
u
How do we implement (elaborate-class-decls!
c-decls) (object-gtclass-name o3_rep) (find-method-
and-apply m1 c3 o3_rep (7 8)) (new-object c3)
9
Flatten Class Fields 5.4.3
Class Representation (c3)
a-class
c3
class-name
super-name
c2
field-length
5
field-ids
z
x
y
y
x
methods
Object Representation (o3)
How do we implement (elaborate-class-decls!
c-decls) (object-gtclass-name o3_rep) (find-method-
and-apply m1 c3 o3_rep (7 8)) (new-object c3)
a-part
c3
class-name
fields
32
31
22
12
11
x
z
y
x
y
5.4.4 flattens class methods
c1
c3
c2
Write a Comment
User Comments (0)
About PowerShow.com