MohamedAbbas
MohamedAbbas

Reputation: 1161

class diagram Composition Relationship

Should the owner have an attribute of the owned object type in a class diagram composition relationship? Or is having a key or related property considered a composition, too?

My example is:

I have two classes "user" and "image". The user logically has an image. In the code the user class contains an attribute for the image name (the key) but not an object of type "image".

Upvotes: 0

Views: 103

Answers (1)

PsiX
PsiX

Reputation: 1681

The relationships in UML should be mostly independent of the actual implementation. What the composition relationship expresses is a lifetime dependency.

Objects that are composed are responsible for creation, usage and destruction of the owned objects. Whether it is realized through a reference to the actual object or a placeholder (in your case the name of the image), is not that much of a difference.

In a composition the owned class ("image") should not be able to exist without its owner class ("user"). In your case I'd say it is possible, so you should change the relationship in your model accordingly.

Upvotes: 1

Related Questions