325Re: [sicp-vsg] exercise 2.76
- Aug 21, 2005
> But what about the second question where new operations are added mostPerhaps. But a potential problem is that should a new type be added in
> often? At first it looks like the answer's the same, either
> data-directed or message-passing. But you might make an argument for
> explicit dispatch if very very few data types are being added and you
> want to organize your code in terms of functionality rather than
the future, you've got all those explicit ops to go and edit, so I'd
say that explicit dispatch isn't a good idea in this case.
The dispatch code is repeated code. All the approaches require
boilerplate of some kind, but the explicit dispatch requires repeated
code which contains the list of types. My alarm bells would start to
ring once I'd typed out that list twice.
Hmm...why don't I get the same worry about repeating the operation
names in the data-directed or message passing cases? Perhaps its
because that these types need to declare somehow what they can do?
- << Previous post in topic Next post in topic >>