Python Programming from First Principles: Learn to Code, Think Computationally, and Solve Real-World Problems
PDFEPUB
BOOK 000 · CHAPTER 7 · Object Diagram

Object Diagram

An object diagram shows selected instances and values at one moment. An underlined label such as ada : Student names the object and its class. Lines connect those particular instances.

ada : Studentstudent_id = "S001"name = "Ada Lovelace"cs101 : Coursecourse_code = "CS101"title = "Intro to CS"credits = 6enr1 : Enrollment_grade = "A"studentcourse

Unlike a class model, this is a snapshot of particular objects at one moment. student_id = "S001" is a current value, not a type declaration. The line labelled student connects the Enrollment object to Ada; the line labelled course connects it to CS101. These lines represent the references stored by that enrollment, not a sequence of function calls.

The snapshot follows ada.enroll(cs101) and enr1.set_grade("A"). enr1.student refers to Ada, and enr1.course refers to CS101.

Predict: what value would _grade show before grading? The next example creates this snapshot in Python.