So I have a function lets say:
def func(self):
ls = []
#do something to ls
return self.ListParser(ls)
def ListParser(self, ls):
files = []
# do some stuff with ls and files
return files
So in the uml class diagram what do I put for return type if it looks like this:
+
func(self): return type
do I put:
+
func(self): ListParser(ls)
or
+
func(self): files[]
Do I put what it will eventually return or the function call.
Thank you.
Actually your question is not correct. Your function func
does not return a function, but the result of a function. To my knowledge there is no common type representing a function. The return of an operation is a Type
9.6.4 Notation If shown in a diagram, an Operation is shown as a text string of the form:
[<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’ [‘:’ [<return-type>] [‘[‘ <multiplicity-range> ‘]’] [‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]]
...
•
<return-type>
is the type of the return result Parameter if the Operation has one defined.
So you are more or less free in inventing you own notation if you want to return a function. That would in most case be language specific (e.g. in Swift you would show that as () -> ()
for a void function without parameters; for Python you could 'invent' the notation <func>
to return a function).
Now, as already said, you do not return a function, but the result of a function. And that seems to be an array. I would assume an array of strings. So I would show that as
assuming the above is part of the class ClassWhatEver
. Note that the signature does not list the names, but the types, so for the self
you would show the class name. It would also be possible to leave that away if you are modeling towards Python and have some modeling guidelines that say so. In that case you would need to distinguish static functions by stereotyping them like so:
N.B. You named ListParser
with a capital L
. Though you should stick to common naming rules and only use capital first char for classes, types, etc and not for operations. So you should name it listParser
instead.