(define (perimeter rect)
(* 2
(+ (length rect) (breadth rect))))
(define (area rect)
(* (length rect) (breadth rect)))
;;universal selectors
(define (length rect)
(rect 'length))
(define (breadth rect)
(rect 'breadth))
;; representations..
;; a representation that takes length, and breadth of
;; the rectangle as input
(define (make-rect l b)
(define (dispatch msg)
(cond
((eq? msg 'length) l)
((eq? msg 'breadth) b)
(else (error "Message not recognized!"))))
dispatch)
If we think carefully, then the bean style of data abstraction we use in java when there are just getters/setters in the class implements this message passing style for data abstraction.
No comments:
Post a Comment