Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Depicting static polymorphism in a UML class diagram

I have an object which is instantiated during compilation according to the build configuration. As far as the surrounding software considered, the object exposes the same interface. I would like to model the fact that the instantiation decision is taken during compilation (i.e. static polymorphism), as opposed to the usual dynamic polymorphism.

Is there a way to depict a static polymorphism in UML class diagram?

Here is more or less what I need:

enter image description here

Obviously, only one of the above type definitions will be instantiated at compilation.

like image 365
SomeWittyUsername Avatar asked May 12 '13 09:05

SomeWittyUsername


People also ask

How do we indicate static on a UML class diagram?

Class (i.e. static) methods and fields are indicated by underlining. Constant (i.e. final) fields are indicated via naming convention: constants should be in ALL_CAPS.

What is polymorphism in class diagram?

Polymorphism is writing code using a superclass that can be executed for any object of a subclass. For example, an array of Polygons might include Rectangle objects, Square objects, Triangle objects, etc. ( Violet UML Diagram) Each subclass of Polygon might inherit or have its own method for computing the area.

Which of the UML diagram is a static diagram?

Class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for visualizing, describing, and documenting different aspects of a system but also for constructing executable code of the software application.

What is class diagram in UML with example?

What are the Class Diagrams? Class diagrams are the main building block in object-oriented modeling. They are used to show the different objects in a system, their attributes, their operations, and the relationships among them.


3 Answers

I would use stereotypes to solve the problem. So you can mark dynamic and static

like image 29
user2004268 Avatar answered Nov 08 '22 22:11

user2004268


I think the UML representation will be same for static and dynamic polymorphism. UML is about how classes interact at runtime -- I don't believe there's a UML format for describing templates, but I could be wrong.

like image 163
Chirag Desai Avatar answered Nov 08 '22 22:11

Chirag Desai


I think your diagram is fine. What you are describing seems to best described as a sequence diagram describing your compilation process. (Kind of like how you'd draw a factory sequence diagram I guess)

As you correctly point out, interactions at runtime occur with some unknown concrete thing behind the interface, so you never really have to bother about concrete classes in those sequence or interaction diagrams. It's completely irrelevant there.

If there is a good deal of this happening then a deployment diagram might also be a good idea to help show what concrete implementations occur under what circumstances.

You'd want to document classes that implement your interfaces of course, and that's just a normal class diagram exactly as you've drawn it.

like image 2
LoztInSpace Avatar answered Nov 08 '22 21:11

LoztInSpace