Relationships and dispatch
What is association?
On this page
An association describes a meaningful relationship between instances. A librarian can be assigned to several branches and a branch can have several librarians. A diagram can express these multiplicities even when the implementation stores assignment rows instead of references in both objects.
Relationship diagram
Worked example
Pythonfrom dataclasses import dataclass
@dataclass
class Editor:
name: str
@dataclass
class Manuscript:
title: str
editor: Editor
editor = Editor("Alex")
draft = Manuscript("Queueing", editor)
assert draft.editor is editorExplore class relationships in the OOP Playground