Object-Oriented Programming

Object-Oriented Programming (OOP) is a method of data abstraction that allows one to write flexible programs that are independent of the implementation of the data on which they operate.

Consider ways of implementing vectors:

If we write a program that obtains the x value from a vector v by doing (car v), that program will work for some kinds of vectors but not for others.

If, instead, we use a message (send v 'x), then our program can work for all the kinds of vectors (even new ones to be added later).

(define (vector-x self) (cadr self))

(define (polar-x self) (* (cadr self) (cos (caddr self))) )

Contents    Page-10    Prev    Next    Page+10    Index