Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML - Object Method Returns a Collection

How can I indicate that a method will return a collection of objects in UML? Is there a better way to explain the relationship than to have a collection class as a return type?

like image 329
derekerdmann Avatar asked May 29 '10 23:05

derekerdmann


People also ask

What is object model in UML?

In UML models, objects are model elements that represent instances of a class or of classes. You can add objects to your model to represent concrete and prototypical instances. A concrete instance represents an actual person or thing in the real world.

What are methods in UML?

A UML method is the implementation of an operation; if constraints are defined, the method must satisfy them. A method may be illustrated several ways, including: in interaction diagrams, by the details and sequence of messages. in class diagrams, with a UML note symbol stereotyped with «method»

What is object diagram in UML with example?

What is an object diagram in UML? A UML object diagram represents a specific instance of a class diagram at a certain moment in time. When represented visually, you'll see many similarities to the class diagram. An object diagram focuses on the attributes of a set of objects and how those objects relate to each other.

What is the purpose of object diagram?

In UML, object diagrams provide a snapshot of the instances in a system and the relationships between the instances. By instantiating the model elements in a class diagram, you can explore the behavior of a system at a point in time.


1 Answers

I am coming to this a little late, since I was looking for an answer to a similar question. I am writing this incase somebody else is looking for a similar answer.

Do you want to indicate that a method returns a collection of a specific type? If so, for a method you should be able to set the type of the return parameter and the multiplicity of the return parameter to 0..* or 1..*. This would indicate that the method returns the specified type and that it has whatever multiplicity you state.

E.g. using the Library <>--- Book example, suppose there is a method on Library called GetBooks that takes a string parameter, author name, and returns a collection of Book instances. The UML would look something like this:

Library +GetBooks(authorName: string) : Book[0..*]

Your UML diagramming tool should support this; I am using Magic Draw. This UML states that GetBooks returns 0 or many Book instances. It is now up to programmer to decide how to implement the return parameter in the implementation language (as stated above by Simon).

like image 151
RobertMS Avatar answered Sep 22 '22 01:09

RobertMS