3.5.4 Representing Abstract Classes in Class Diagrams

Represent Abstract Classes in Class Diagrams

The Wildcats training design needs a shared Player type, but each concrete role must supply its own training task. Read the abstract contract, separate it from an implemented operation, and then represent both in Violet.

Read the Code Before Drawing

These complete declarations define an abstract Player and one concrete Goalkeeper. Name is inherited storage. GetTrainingTask has a required string result, but its base declaration has no body. The override supplies the concrete behavior.

Source to translate
public abstract class Player
{
    public string Name;

    public abstract string GetTrainingTask();
}

public class Goalkeeper : Player
{
    public override string GetTrainingTask()
    {
        return "Practice saves";
    }
}
Rewrite the Meaning in Ordinary Words
The same design in ordinary words
Define Player as an abstract base type
Keep the shared Name field in the base type
Require a GetTrainingTask operation with a string result
Leave that operation without a base implementation
Define concrete Goalkeeper as a derived Player
Supply its override returning Practice saves

These words describe the class contract, not a sequence of runtime actions. Identify the types, stored members, operation inputs and results, and relationships before choosing compartments and connectors.

Map the Source to Class Boxes and Connectors
Build the Diagram in Violet
  1. Create a class diagram in Violet with Player and Goalkeeper.
  2. Identify the base class as abstract. Use the course's visible marker in its heading, Player <abstract>, and add attribute +Name : string.
  3. In Player's operation compartment enter +GetTrainingTask() : string <abstract>. The marker records the missing base implementation; do not invent a base return value.
  4. In Goalkeeper enter +GetTrainingTask() : string. Add a note Overrides the abstract operation; returns Practice saves. Draw solid generalization with its hollow triangle at Player.
  5. Save and add a brief notation note: <abstract> is the Violet text marker for an abstract class or operation; standard UML can use italics. Do not underline the entries, which would mean static.
Compare the Completed Soccer Diagram

Compare this reference with the diagram you built in Violet. Layout may differ; the source meaning, labels, and relevant connections should agree.

Abstract Player declares Name and abstract GetTrainingTask. Concrete Goalkeeper inherits Player and implements the operation returning Practice saves.
An abstract contract and a concrete goalkeeper implementation
  • New
  • Changed
  • Removed
Read the Contract One Part at a Time

Read from Goalkeeper up the generalization connector to Player. The derived class inherits Name and must supply GetTrainingTask. The expression new Goalkeeper() is permitted, but new Player() is not because Player is abstract.

A Player-typed reference can still point to a Goalkeeper. Calling GetTrainingTask through that reference invokes the concrete override and returns Practice saves; an abstract base type does not mean every reference declared with that type is null.

Verify the Drawing Against the Source
Predict and Check a Small Change