Association Classes of UML

来源:互联网 发布:淘宝闲鱼客户端 编辑:程序博客网 时间:2024/05/17 23:41

Association Classes

  • Association classes allow you to add attributes, operations, and other features to associations, as shown in attached file (Association Classes.jpg). We can see from the diagram that a person may attend many meetings. We need to keep information about how awake that person was; we can do this by adding the attribute attentiveness to the association.
  • Attached file (Association Classes02.jpg) shows another way to represent this information: Make Attendance a full class in its own right. Note how the multiplicities have moved.
  • What benefit do you gain with the association class to offset the extra notation you have to remember? The association class adds an extra constraint, in that there can be only one instance of the association class between any two participating objects.
  • Implementing association classes isn't terribly obvious. My advice is to implement an association class as if it where a full class but to provide methods that get information to the classes linked by the association class. So for Figure 5.12 (Association Classes.jpg), I would see the following methods on Person:

class Person

List getAttendances(String meeting)

List getMeetings()

  • This way, a client of Person can get hold of the people at the meeting; if they want details, they can get the Attendances themselves. If you do this, remember to enforce the constraint that there can be only one Attendance object for any pair of Person and Meeting. You should place a check in whichever method creates the Attendance.

The information get from UML Distilled. 

 

Summary: association classes is likely make which as a full class, but to provide methods that get information to the classes linked by the association class.