dok
dok

Reputation: 391

when to use association classes in a class diagram?

From what I understand, association classes are based on describing the associations between two classes with attributes, generally speaking they are used when

  1. cardinality is many to many
  2. in case 1,1 is not used 3)1 * in this case it is up to the designer to decide

otherwise it is possible to transform the association class into a class or an associative class that connects the other two classes with cardinalities 1,* and * 1.

another question if I have an attribute in the optional association class, which only applies in some cases and which takes up a lot of space for me, could I handle it by detaching it from the class and create a class linked to the association class or create a new association with just that attribute?

Upvotes: 0

Views: 60

Answers (1)

Christophe
Christophe

Reputation: 73530

The association class is not only suitable for many to many associations. Association classes are suitable for any kind of multiplicities. You may for example very well have association-class attributes in a one-to-one association that do not belong to any of the associated classes. While you may very well in the implementation arbitrarily host theses attributes in the one or the other class, in the model if would be better to show the separation of concerns.

Regarding the optional attributes, you may indeed put them in a separate class linked to the association class. However keep in mind that properties and attributes are very close concepts: having any attribute in a class is equivalent to have the class with an association to the type of that property, where the assotiation end is owned by the class. In other words, doing sonwill not fundamentally change the semantics of the model, but mainly how you visualise it.

Upvotes: 0

Related Questions