Home Tutorials Python OOP Concepts Association
Association

Association


32. Association

Association describes a general relationship between objects where they interact with each other. It is broader than composition and aggregation.

Syntax

class A:
    pass

class B:
    pass

Example

class Teacher:
    def teach(self):
        print("Teacher teaches")

class Student:
    def learn_from(self, teacher):
        teacher.teach()

teacher = Teacher()
student = Student()
student.learn_from(teacher)

Output

Teacher teaches
Example

🏋️ Test Yourself With Exercises

Take our quiz on Association to test your knowledge.

Browse Quizzes »