Representing class variables and methods in UML
Asked Answered
S

1

5

Many programming languages allow you to define class/instance methods, and the same for attributes. E.g. Python, Smalltalk. I have the concepts. E.g. for instance variables, every object has it’s own copy of the variables. Class variables only have one copy of the variables shared with all instances of the class.

My doubt is: how do I represent class methods and class attributes in UML? I was thinking in represent it through static, as in C++, Java, and C#, but is it ok? "static" and "class" are the same in UML?

Sparge answered 4/10, 2015 at 18:10 Comment(0)
C
12

Static attributes/operations1 need to be underlined. See also Class diagrams

enter image description here

1The term method is used for behavior (the howto) in UML. An operation is the term used in UML for a BehaviorialFeature that can be called on an interface (which is what you find in the compartment underneath the attributes).

Cascarilla answered 4/10, 2015 at 19:30 Comment(2)
If it's a UML for Python language for example, which has instance methods, class methods, and static methods: how would you differentiate between the class methods and the static methods? Or perhaps you wouldn't differentiate and simply underline both @classmethod- and @staticmethod-decorated methods of a Python class?Earthen
@Earthen both decorators are merely identical, juat thw @static does not have a self as first parameter. So from a UML view they are just static operations.Cascarilla

© 2022 - 2024 — McMap. All rights reserved.