I was reading through a tutorial on UML Class diagrams and I'm having problems understanding Association Classes and why this MileageCredit
class isn't part of the FrequentFlyer
class in the below example (taken from figure 11 of the tutorial here):
Assuming that it's a one-to-one relation between FrequentFlyer and MileageCredit (if a person had two FrequentFlyer memberships they'd still have different frequentFlyerNumber numbers) then I would just put these baseMiles
and bonusMiles
properties in the FrequentFlyer Class itself.
Could someone please explain why this is wrong?
MileageCredit is an AssociationClass, which means this is simultaneously an Association (linking) Flight and FrequentFlyer) and a class that describes this Association. This fact is depicted by a dashed line connecting the class and the association. Note that acording to the UML specification those class and association together create one entity.
In your example there is Association (that is called MileageCredit) between FrequentFlyer and a Flight. You may assume that this shows a Flight taken by a FrequentFlyer. As for these Association you need additional information (number of award and bonus miles that are awarded to the FrequentFlyer for this Flight) this association has this extra Class describing this information.
If you created baseMiles and bonusMiles on FrequentFlyer that would have absolutely no relationship to the Association - it would be only information about total points awarded to the FrequentFlyer.