3.4. UML Class Diagram

3.4.1. Attributes

class Astronaut:
    firstname: str
    lastname: str
```mermaid
classDiagram

class Astronaut {
    firstname: str
    lastname: str
}
```
../../_images/uml-classdiagram-attributes.png

3.4.2. Methods Without Parameters

class Astronaut:
    def say_hello():
        pass
```mermaid
classDiagram

class Astronaut {
    say_hello()
}
```
../../_images/uml-classdiagram-method-noparams.png

3.4.3. Methods With Parameters

class Astronaut:
    def say_hello(firstname: str, lastname: str):
        pass
```mermaid
classDiagram

class Astronaut {
    say_hello(firstname: str, lastname: str)
}
```
../../_images/uml-classdiagram-method-params.png

3.4.4. Method Return Type

class Astronaut:
    def say_hello() -> str:
        pass
```mermaid
classDiagram

class Astronaut {
    say_hello() str
}
```
../../_images/uml-classdiagram-method-return.png

3.4.5. Abstract Methods

from abc import abstractmethod, ABCMeta

class Astronaut(metaclass=ABCMeta):
    @abstractmethod
    def say_hello():
        pass
```mermaid
classDiagram

class Astronaut {
    say_hello()*
}
```
../../_images/uml-classdiagram-method-abstract.png

3.4.6. Static Methods

class Astronaut:
    @staticmethod
    def say_hello():
        pass
```mermaid
classDiagram

class Astronaut {
    say_hello()$
}
```
../../_images/uml-classdiagram-method-static.png

3.4.7. Types

class Astronaut:
    firstname: str
    lastname: str

    def say_hello(name: str) -> str:
        pass
```mermaid
classDiagram

class Astronaut {
    firstname: str
    lastname: str

    say_hello(name: str) str
}
```
../../_images/uml-classdiagram-types.png

3.4.8. Access Modifiers

  • + - Public

  • - - Private

  • # - Protected

  • ~ - Package/Internal

3.4.9. Access Modifiers - Public

class Astronaut:
    firstname: str
    lastname: str

    def say_hello() -> str:
        pass
```mermaid
classDiagram

class Astronaut {
    +firstname: str
    +lastname: str
    +say_hello() str
}
```
../../_images/uml-classdiagram-accessmodifiers-public.png

3.4.10. Access Modifiers - Protected

class Astronaut:
    _firstname: str
    _lastname: str

    def _say_hello() -> str:
        pass
```mermaid
classDiagram

class Astronaut {
    #firstname: str
    #lastname: str
    #say_hello() str
}
```
../../_images/uml-classdiagram-accessmodifiers-protected.png

3.4.11. Access Modifiers - Private

class Astronaut:
    __firstname: str
    __lastname: str

    def __say_hello() -> str:
        pass
```mermaid
classDiagram

class Astronaut {
    -firstname: str
    -lastname: str
    -say_hello() str
}
```
../../_images/uml-classdiagram-accessmodifiers-private.png

3.4.12. Cardinality

  • 1 - Only 1

  • 0..1 - Zero or One

  • 1..* - One or more

  • * - Many

  • n n - {where n>1}

  • 0..n - zero to n {where n>1}

  • 1..n - one to n {where n>1}

3.4.13. Boxes and Arrows

../../_images/uml-classdiagram-usecase-01.jpg

3.4.14. Use Cases

../../_images/uml-classdiagram-usecase-02.png
../../_images/uml-classdiagram-usecase-03.png
../../_images/uml-classdiagram-usecase-04.png
../../_images/uml-classdiagram-usecase-05.png
../../_images/uml-classdiagram-usecase-06.png
../../_images/uml-classdiagram-usecase-07.png
../../_images/uml-classdiagram-usecase-08.jpg
../../_images/uml-classdiagram-usecase-09.jpg
../../_images/uml-classdiagram-usecase-10.png

3.4.15. Django

../../_images/uml-django.png
../../_images/uml-django-models.png