Question

I have an abstract parent class Server and 3 subclasses InternalServer, ExternalServer and LoggableInternalServer. Server has the public abstract method receiveClient().

The application has a list of Server which contains a number of objects of the three aforementioned types. This list is iterated and the receiveClient() method is called in each iteration. The implementation of receiveClient() varies depending on the subclass.

Is there a way to represent this polymorphic behaviour using a Sequence Diagram? If not, what other diagram could I use to document this behaviour?

Was it helpful?

Solution

There is a way to represent this polymorphic behavior using a Sequence Diagram. The polymorphic invocations are modeled by multiples scenarios controlled by the guard conditions. Therefore, for each polymorphic scenario, the dynamic binding (polymorphic invocation) is represented for a "scenario box". So, this is a single diagram to show polymorphic invocations for your question.

enter image description here

So, even though this model to answer your question, it is not a clear solution, because it is not-trivial to represent polymorphism in a sequence diagram. Finally, a similar discussion is on the question How to visualize polymorphic invocations in a single diagram?.

OTHER TIPS

You could start the lifeline at point of object creation showing a message from the sender that creates the instance of the classifier. You could mix this with an ALT fragment to show the different implementations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top