Define a schema using ODL
We want to modelize a very simple university environment:
- A course is caracterized by a title and a description
- A student is caracterized by a firstname, a lastname and a registration year
- A teacher is caracterized by a firstname and a lastname
- A teacher is in charge of one or several courses
- A student is registered to one or several courses
The following schema implements the previous model by introducing:
- The given attributes: firstname, lastname, begin_year, title, description
- A superclass Person which factorizes the firstname and lastname attributes of students and teachers
- Relationships between:
- Student and registered courses (called “registered to”)
- Teacher and in charge courses (called “in charge”)
Here is the Object Definition Language (ODL) implementation of the previous model:
class Person {
attribute string firstname;
attribute string lastname;
};
class Student extends Person {
attribute short begin_year;
relationship set<Course *> courses inverse students;
};
class Course {
attribute string title;
attribute string description;
relationship set<Student *> students inverse courses;
relationship Teacher *teacher inverse courses;
};
class Teacher extends Person {
relationship set<Course *> courses inverse teacher;
};
View the ODL file.
A few comments:
- The inheritance between the classes
StudentandPersonand betweenTeacherandPersonis indicated by theextendskeyword. - The
set<Course *> coursesattribute in theStudentclass and theset<Student *> studentsattribute in
theCourseclass denote the relationship between theStudentand its registered courses - The
set<Course *> coursesattribute in theTeacherclass and theTeacher *teacherattribute in the
Courseclass denotes the relationship between theTeacherand its in chargeCourses - The inverse directives on the relationship attributes are there to indicate to EyeDB to maintain the referential integrity of the relationships
To enter this schema in a database, we must use the eyedbodl tool which checks the syntax and semantics of the schema and in case of succes submit the given schema to the given database.
