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

Information or Data Model

An information model identifies the data and relationships a system needs. An entity–relationship (ER) diagram is one way to express it.

Here, Student has an ID and name; Course has a code, title and credits; Enrollment connects one student to one course and may hold a grade.

An entity is a kind of thing for which we keep records; its box lists the fields in those records. This ER diagram uses crow’s-foot notation for relationship counts: the branching foot means many, a small circle permits zero, and two bars mean exactly one. Thus o{ means zero or many and || means exactly one. Read the symbol at the far end of a line to answer “how many of those records can relate to one of these?”

For example, start at Student and follow the line to Enrollment: a student can have zero or many enrollment records. Starting at Enrollment and following it back to Student gives exactly one student. The Course link follows the same rule. The field label PK means primary key: the value, or combination of values, that identifies a record uniquely. FK means foreign key: a value referring to an identifying field in another entity. The pair (student_id, course_code) is Enrollment’s composite primary key; the two fields together identify one enrollment, although neither field alone is unique across all enrollments. Each also refers to its Student or Course record. These are the model’s identification rules; the application must enforce them. str denotes text, int an integer and None an absent grade. These field types describe the data; they do not by themselves implement validation in Python.

Studentstudent_id : str «PK»name : strCoursecourse_code : str «PK»title : strcredits : intEnrollmentstudent_id : str «PK, FK»course_code : str «PK, FK»grade : str or None

One student can have many enrollments; one course can also have many. Each enrollment refers to exactly one of each. The grade is absent until assigned.

Try it: add a second student to CS101 on paper. Which entity needs a new record? Next, add operations to turn the data model into a class model.

For the relationship symbols, see PlantUML’s Information Engineering notation. This is an ER data model, using the same visual style as our UML diagrams.