Browse OOP reference
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

Manuscripteditor: EditorEditorname: stredited by

Worked example

Python
from 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 editor

OMG Unified Modeling Language specification

Explore class relationships in the OOP Playground

What is aggregation?What is method overloading?What is the object-relational impedance mismatch?

All OOP questions

Search ObjectFAQ