Frage

The uml class diagram of a car store

Please neglect any other arrow excluding the single simple arrow on which 1..1 or anything like that is written at the end

I have refered to many websites and many books giving introductions to UML 2.0 and i came across two conventions used

when two classes are connected by a single line without arrow and either 1..1, 1..*, etc is written at the end of line, then

Assuming that at the end of line joining purchasePlan and User the term is 1..* not 0..*

1) according to one convention we create PurchasePlan object's array in User class according to diagram and one object of User in PurchasePlan

2) according to second convention we create only array of objects of purchaseplan in User, but not user's object in PurchasePlan

So which convention is the most widely used or the standard one?

War es hilfreich?

Lösung

What you are looking at there is a bi-directional association. This means convention (1) is appropriate for this relationship. If the association had an arrow then the second approach would apply.

The "0..*" is significant in that a User can have no referenced purchase plans (i.e. its PurchasePlan array can be empty). The corresponding User field in every PurchasePlan would still need to be populated (not null) in order to adhere to the bi-directional relationship; this rejects the possibility of "orphaned" purchase plans.

Andere Tipps

The first option would create a cyclic dependency. This is discouraged because you get a higher coupling and the maintainabilty of your code degenerates. Your two options are creating a collection of PurchasePlan in your User or a single User in each PurchasePlan. Which one you use depends on your domain. Ask yourself if you have to get all PurchasePlan for a User or the other way around more often.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top