2.4. UML Class Diagram

2.4.1. Attributes

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

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

2.4.2. Methods Without Parameters

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

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

2.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

2.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

2.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

2.4.6. Static Methods

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

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

2.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

2.4.8. Access Modifiers

  • + - Public

  • - - Private

  • # - Protected

  • ~ - Package/Internal

2.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

2.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

2.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

2.4.12. Boxes and Arrows

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

2.4.13. 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

2.4.14. Django

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

2.4.15. Generate from code

$ pyreverse -o png -p mymodule .