In a java code the Printer class has a print method. This print method, rather than performing the print itself, delegates to class RealPrinter. To the outside world it appears that the Printer class is doing the print, but the RealPrinter class is the one actually doing the work. Draw the UML class diagram showing Delegation.
The way that the question is formulated makes it look like a homework problem. If it is, be aware that the answer might not match with what your instructor expects.
A class diagram shows the static structure of how classes relate to each other, but the fact that a method in class A delegates its work to a method in class B is unrelated to the static structure. For that reason, delegation is not shown in a class diagram.
Given the information presented in the question, I would create two diagrams:
- A class diagram showing
RealPrinterwith a composition relation between them (
- A sequence diagram for the method
Printer::printshowing that it delegates to