Reputation: 85
I know the basic format of UML and I know you typically include the variables defined for the class. My question is, do you include variables that are defined within methods of the class?
In my program I have two classes, BabyName and NameFinder. BabyName is an object and my UML has all of its variables included. The only variables in NameFinder are those that are defined in main() and other methods. Would those be included?
Upvotes: 3
Views: 3049
Reputation: 82
Let's call things by their name.
Is not told variables for the class, that is called attribute (or you can call them fields)
The parameters of method should not be included in the section of attributes. Doing so is a mistake. UML is flexible, but also has its rules. And this is one of those.
The explanation is simple: The parameters are local to the method and outside it does not exist. Therefore it makes no sense to define the attributes section. Unlike the case with attributes, they are "global" scope throughout the class. While there is an instance of the class at all times(1) can be accessed attributes.
(1) Well, actually not at all times. Only the attributes of simple types. If the attribute is a pointer type or a class (to name two examples) is different and depends and that memory has been reserved and is available instance.
Upvotes: 0
Reputation: 1248
In UML, you don't need to declare variables that are local to the methods in a class. Those variables don't have to do with the state of an Object, they're simply temporary variables for executing a method.
If NameFinder
has no Class-level variables, they don't need to be included.
Upvotes: 3