I have to model a system where an object of the class Person
will invoke the static method getBook(...) : Book
on the class Book
which will return an instance of a particular book.
How do you reference the book instance obtained by the operation?
As of now, I can think of two approaches, neither of which I have ever seen/used, which is why I am looking for the correct approach.
The first approach is to invoke methods directly on the book instance obtained, e.g. if the reference returned by getBook(...) : Book
is named matchingBook
, I would use matchingBook.doSomething(...)
, much like having a local variable.
The second way, which I find more in the line of sequence diagrams is to let the book instance returned by the operation appear with its own lifeline, e.g. next to the Book class, and referencing it with an arrow labeled doSomething(...)
.
However, with the second approach, it is not that obvious that this object is in fact the one returned by the operation.