Search code examples
umlclass-diagramflowchart

Can i identify in UML that method calls method from another class


I represented this chunk of code:

class Enemy{
    int _health;
    void Attack(){
        Player.GetDamage(25);
    }
}

class Player{
    int _health;
    public void GetDamage(int amount){
        _health -= amount;
    }
}

in UML like this:

enter image description here

Is it right representation? I am new in UML and don't know if i'm doing things right.


Solution

  • No, this is not correct. The association is wrong. This is only a dependency, which you need to show as dashed arrowed line. A class diagram only shows a static structure (i.e. how the classes relate to each other).

    You show the dynamic part of calling in a sequence diagram:

    enter image description here

    The Actor1 is some automata in the system which triggers the attack.