CSC 4101 Chapter : Homework 3 Solutions

11 views8 pages
15 Mar 2019
School
Course
Professor

Document Summary

1) we would simply pass the tree node as an argument to the multimethod. Here"s how this would work in brew (an extension of java i"m working on): generic void print(node); The generic function declaration tells the compiler to generate code for a multimethod dispatch instead of treating these print methods as overloaded. The multimethod dispatch mechanism would select the apropriate method at run time based on the run-time type of the argument in a similar manner as how virtual function dispatch works. In the design patterns literature there"s the visitor design pattern that explains how to achieve a similar effect without multimethods. Multimethod dispatch could be implemented in a similar manner as virtual function dispatch, i. e. , with a table lookup. In the case of the print method it would be a 1-dimensional table. In general, it would be an n-dimensional table for a function with n parameters. Another implementation would be for the compiler to generate an if-then-else chain.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers