L145OOL - Prasad L145OOL 1 Managing Environments An...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Prasad L145OOL 1 Managing Environments An Exercise in the Design, Analysis, Specification, and Implementation of the Core of an OOP Language. Object-Oriented Language Prasad L145OOL 2 Interpret = Compile + Run Compiler OOPL program object code Parser I nterpreter Scheme System OOPL program Abstract syntax Abstract machine Prasad L145OOL 3 • An object is a collection of operations that share state. The object exists at run-time. • A class is a textual description of the state variables ( fields ) and the operations ( methods ). • A class is an implementation of an ADT . • A module is a syntactic mechanism for grouping related elements, and forms the basis for enforcing information hiding. Prasad L145OOL 4 Introducing objects and classes into the Language • Class definition (via Inheritance) – class variables (** not supported but can be easily incorporated **) – instance variables ( state ) – assignments ( state changes ) – method definitions – method invocations – initialization • Object creation (instantiation) Prasad L145OOL 5 Additional Syntax ( define the-grammar ’( (program ((arbno class-decl) expression) a-program ) . . . (class-decl ("class" identifier "extends" identifier (arbno "field" identifier) (arbno method-decl) ) a-class-decl ) (method-decl ("method" identifier "(" (separated-list identifier ",") ")" expression) a-method-decl ) (expression ("new" identifier "(" (separated-list expression ",") ")") new-object-exp ) (expression ("send" expression identifier "(" (separated-list expression ",") ")") method-app-exp ) (expression ("super" identifier "(" (separated-list expression ",") ")") super-call-exp ) ) ) ) Prasad L145OOL 6 Example : Object and Class class c1 extends object field i field j method initialize (x) begin set i = x; set j = -(0,x) end method countup (d) begin set i = +(i,d); set j = -(j,d) end method getstate () list(i,j) let t1 = 0 t2 = 0 o1 = new c1(3) in begin send o1 countup (2) set t1 = send o1 getstate () list(t1,t2) end Prasad L145OOL 7 Example : Message Passing Style class interior_node extends object field left field right method initialize (l, r) begin set left = l; set right = r end method sum () +(send left sum(), send right sum()) class leaf_node extends object field value method initialize (v) set value = v method sum () value let o1 = new leaf_node(3) o2 = new interior_node( o1, o1) in send o2 sum() Prasad L145OOL 8 Example : Inheritance class point extends object field x field y method initialize (ix, iy) begin set x = ix; set y = iy end method move (dx, dy) begin set x = +(x,dx); set y = +(y,dy) end method getlocation () list(x,y) class colorpoint extends point...
View Full Document

This note was uploaded on 06/02/2011 for the course CS cs784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 26

L145OOL - Prasad L145OOL 1 Managing Environments An...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online