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:
Obviously, only one of the above type definitions will be instantiated at compilation.
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.
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.
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 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.
I would use stereotypes to solve the problem. So you can mark dynamic and static
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With