umlmemberclass-diagrammultiplicity

How to show that there's exactly one element in multiple member collections that meets given criteria in UML?


I have a UML diagram where a football team consists of field players (10 or more) and goalkeepers(1, 2, or 3). How can I show using UML that in a team one of the players is the skipper?

enter image description here


Solution

  • With your current model

    With your given classes and associations, you would express this as a constraint:

    A Constraint is an assertion that indicates a restriction that must be satisfied by any valid realization of the model containing the Constraint.

    A constraint is indicated as an expression between curly braces { ... } that corresponds to a boolean expression expected to be true. It can be:

    I expressed these constraints with the FootballTeam context (i.e. constraint attached to that class), as it is a constraint fo the whole team.

    But...

    The idea of having isSkipper as an attribute of a player does not seem the best idea in view of separation of concerns: the skipper role is dependent on the team, so it would be better shown in an association class.

    Moreover, it is troublesome to have roles such as goal keeper and field player as a specialization, but have the skipper -- yet another role -- as a boolean field might be cumbersome to implement any sound OOP polymorphic design.

    Last but not least, keep in mind that a football team may evolve and that all conditions such as multiplicities might only be fulfilled when thee am is completed, thus creating some disconnection between the model and the reality of your code.

    I therefore would strongly suggest a design like:

    +----------------+ *                    1 +--------------+
    | FootballPlayer |------------------------| FootballTeam |
    +----------------+           :            +--------------+
                                 :
                          +------------+           
                          | TeamPlayer |
                          +------------+           
                                
    

    The TeamPlayer class is about everything that is dependent on the player AND the team.

    Then I'd suggest to design a Role class associated with TeamPlayer. You'd typically have 1 role for a player. The role would be specialized into GoalKeeper vs. FieldPlayer, and you could make Skipper a decorator that can superpose to one of the two other.

    This does not remove the need to express your constraint, but the model would be more powerful. Last but not least, I'd see a /isTeamValid derived attribute that would be true if all your current constraints are fulfilled (including the counts of the player with goal keeper and field player and skipper roles). The advantage is that it lets you to build a team and evolve the composition of a team and roles (