my attempt to do the exercises in sicp.

Monday, August 4, 2008

sicp exercise 2.76

;; Exercise 2.76.  As a large system with generic operations evolves, new types of data objects or new operations may be needed. For each of the three strategies -- generic operations with explicit dispatch, data-directed style, and message-passing-style -- describe the changes that must be made to a system in order to add new types or new operations. Which organization would be most appropriate for a system in which new types must often be added? Which would be most appropriate for a system in which new operations must often be added?

;; explicit dispatch
;; Need to add a dispatch for every type and operation pair

;; data-directed style
;; since this style is additive, the new set of types and its operations can be added seperately from others. the changes are local to the set of new types being added.

;; message-passing style
;; the type takes care of its own operations. the changes are localised to the new type being added.

;; for a system where new types must be often added, message passing is better

;; for a system where new operations must be often added, data directed is better

No comments: