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.

enter image description here

  • 1
    Voting to close as this is clearly a request for others to do the OP's homework for them. – David Arno Sep 6 '16 at 9:43
  • I have a clear understanding of the classes which i have put as a figure while asking the question. The UML class diagram showing the delegation is what i'm looking for. – user6713 Sep 6 '16 at 9:53

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:

  1. A class diagram showing Printer and RealPrinter with a composition relation between them (Printer contains a RealPrinter instance)
  2. A sequence diagram for the method Printer::print showing that it delegates to RealPrinter::print.
  • If this is a homework problem then the OP should probably do a search on the internet using the obscure search term words 'UML delegate'. There's a lot of different ways and diagrams to show the relationship and I'm sure there's probably one in particular that was explained in class which is the expected answer. – Dunk Sep 6 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.