Login :
Password :

Design patterns

Messages relay between nested components

Problem wording :

Design a help manager of a Java application. A help manager allows the show of a help message depending on the objects on which a client has clicked. For example, the "?", sometimes located near the contextual menu of a Windows dialog box, allows the show of the help of the button or the area where we click. If the button on which one clicks does not contain help, it is the area containing which displays its help, and so on. If no object contains help, with final, the manager displays "Not help available for this area". Instantiate your class diagram in a sequence diagram of on the example of a printing window. This window (JDialog) consists in an explanatory text (JLabel), and in a container (JPanel). This last contains a Print button (JButton) and a Cancel button (JButton). The Print button contains help "Launches the impression of the document". The Cancel button, the text as well as the window do not contain help. Lastly, the container contains help "Click on one of the buttons". In the sequence diagram, reveal the scénarios: "The user asks for the help of the Print button", "the user asks for the help of the Cancel button", and "the user asks for the help of the text".

Optimal solution :

Static diagram :

Static diagram

Sequence diagram :

Sequence diagram

A classical instantiation of the pattern.

Alternative solution 1 :

Static diagram :

Static diagram

Sequence diagram :

Sequence diagram

There is a separation between containers and contents. Two issues arise. The first concerns the validity of the solution and the second concerns the interaction with another misaligned pattern presents in the design. We have considered this solution valid even if delegation between content objects is not possible. The problem can be solved by adding a reflexive association on the class Content.

Click here to see the spoiled pattern deduced from this alternative solution

Les têtes de mule
Cédric BOUHOURS
Cédric BOUHOURS
Cédric BOUHOURS