9.4 The Object Database Management Group (ODMG) Model and Object Definition Language (ODL)

The Object Database Management Group (ODMG) was a group of vendors that developed and published standards for OO databases and languages. It was founded in 1991 and published several standards, including the ODMG 3.0 standard, published in 1999, before disbanding in 2001. Its work has been taken over by the OMG. The ODMG established standards for the object data model, the Object Definition Language (ODL), the OQL, and language bindings for C++, Java, and Smalltalk. ODL is a standard language for describing schemas in OO terms, serving the same function that SQL Data Definition Language (DDL) serves. FIGURE 9.6 shows the ODL definition for the revised University schema shown in Figure 9.5.

Line 1. class Person
Line 2. open parentheses extent People
Line 3. key p I d close parentheses
Line 4. open curly brace
Line 5. forward slash asterisk define attributes asterisk forward slash
Line 6. attribute int p I d semicolon
Line 7. attribute string name semicolon
Line 8. attribute Struct A d d r open parentheses string street comma string city comma string state comma string zip close parentheses address semicolon
Line 9. attribute string phone semicolon
Line 10. attribute date birth Date semicolon
Line 11. forward slash asterisk define methods asterisk forward slash
Line 12. int find Age open parentheses close parentheses semicolon
Line 13. close curly brace semicolon
Line 14. class Student extends Person
Line 15. open parentheses extent Students close parentheses
Line 16. open curly brace
Line 17. forward slash asterisk define attributes asterisk forward slash
Line 18. attribute int credits semicolon
Line 19. attribute real open parentheses 3 comma 2 close parentheses g p a semicolon
Line 20. forward slash asterisk define relationships asterisk forward slash
Line 21. relationship Set open angled bracket Class Section close angled bracket takes Class Inverse Class Section colon colon has Student semicolon
Line 22. relationship Set open angled bracket Mark close angled bracket earned Grade Inverse Mark colon colon given Student semicolon
Line 23. relationship Faculty has Advisor Inverse Faculty colon colon advises semicolon
Line 24. forward slash asterisk define methods asterisk forward slash
Line 25. string get Status open parentheses close parentheses semicolon
Line 26. void add Credits open parentheses in int num Credits close parentheses semicolon
Line 27. close curly brace semicolon
Line 28. class Faculty extends Person
Line 29. open parentheses extent Fac close parentheses
Line 30. open curly brace
Line 31. forward slash asterisk define attributes asterisk forward slash
Line 32. attribute enum Faculty Rank open curly brace lecturer comma instructor comma assistant comma associate comma professor close curly brace
Line 33. rank semicolon
Line 34. attribute real open parentheses 8 comma 2 close parentheses salary semicolon
Line 35. forward slash asterisk define relationships asterisk forward slash
Line 36. relationship Department belongs To Inverse Department colon colon has Faculty semicolon
Line 37. relationship Set open angled bracket Class Section close angled bracket teaches Inverse Class Section colon colon has Teacher semicolon
Line 38. relationship Set open angled bracket Student close angled bracket advises Inverse Student colon colon has Advisor semicolon
Line 39. relationship Department chairs Inverse Department colon colon has Chair semicolon
Line 40. relationship Set open angled bracket Evaluation close angled bracket has Evaluation Inverse Evaluation colon colon is Eval Of semicolon
Line 41. forward slash asterisk define methods asterisk forward slash
Line 42. void give Raise open parentheses in float amount close parentheses raises open parentheses Salary out of range close parentheses semicolon
Line 43. forward slash asterisk raises an exception if salary is out of range asterisk forward slash
Line 44. close curly brace semicolon
Line 45. class Undergraduate extends Student
Line 46. open parentheses extent Undergrads close parentheses
Line 47. open curly brace
Line 48. forward slash asterisk define attributes asterisk forward slash
Line 49. attribute string major semicolon
Line 50. forward slash asterisk define methods asterisk forward slash
Line 51. void change Major open parentheses in string new Major close parentheses raises open parentheses Invalid major close parentheses semicolon
Line 52. close curly brace semicolon
Line 53. class Graduate extends Student
Line 54. open parentheses extent Grads close parentheses
Line 55. open curly brace
Line 56. forward slash asterisk define attributes asterisk forward slash
Line 57. attribute string program semicolon
Line 58. forward slash asterisk define methods asterisk forward slash
Line 59. string change Program open parentheses in string new Program close parentheses raises open parentheses Invalid program close parentheses semicolon
Line 60. close curly brace semicolon
Line 61. class Teaching Assistant extends Graduate
Line 62. open parentheses extent T A s close parentheses
Line 63. open curly brace
Line 64. forward slash asterisk define attributes asterisk forward slash
Line 65. attribute string funding Source semicolon
Line 66. attribute real open parentheses 7 comma 2 close parentheses annual Stipend semicolon
Line 67. forward slash asterisk define relationships asterisk forward slash
Line 68. relationship Class Section assists Inverse Class Section colon colon has T A semicolon
Line 69. close curly brace semicolon
Line 70. class Department
Line 71. open parentheses extent Departments
Line 72. key open parentheses dept Code comma dept Name close parentheses close parentheses
Line 73. open curly brace
Line 74. forward slash asterisk define attributes asterisk forward slash
Line 75. attribute string dept Code semicolon
Line 76. attribute string dept Name semicolon
Line 77. attribute string dept Office semicolon
Line 78. attribute string phone semicolon
Line 79. forward slash asterisk define relationships asterisk forward slash
Line 80. relationship Set open angled bracket Faculty close angled bracket has Faculty Inverse Faculty colon colon belongs To semicolon
Line 81. relationship Faculty has Chair Inverse Faculty colon colon chairs semicolon
Line 82. relationship Set open angled bracket Course close angled bracket offers Inverse Course colon colon is Offering semicolon
Line 83. close curly brace semicolon
Line 84. class Course
Line 85. open parentheses extent Courses
Line 86. key c No close parentheses
Line 87. open curly brace
Line 88. forward slash asterisk define attributes asterisk forward slash
Line 89. attribute string c No semicolon
Line 90. attribute string c Title semicolon
Line 91. attribute int credits semicolon
Line 92. attribute string description semicolon
Line 93. forward slash asterisk define relationships asterisk forward slash
Line 94. relationship Set open angled bracket Course close angled bracket has Prerequisite Inverse is Prereq Of semicolon
Line 95. relationship Set open angled bracket Course close angled bracket is Prereq Of Inverse has Prerequisite semicolon
Line 96. relationship Department is Offering Inverse Department colon colon offers semicolon
Line 97. close curly brace semicolon
Line 98. class Class Section extends Course
Line 99. open parentheses extent Sections close parentheses
Line 100. open curly brace
Line 101. forward slash asterisk define attributes asterisk forward slash
Line 102. attribute string section Code semicolon
Line 103. attribute string schedule semicolon
Line 104. attribute string room semicolon
Line 105. forward slash asterisk define relationships asterisk forward slash
Line 106. relationship Set open angled bracket Student close angled bracket has Student Inverse Student colon colon takes Class semicolon
Line 107. relationship Faculty has Teacher Inverse Faculty colon colon teaches semicolon
Line 108. relationship Teaching Assistant has T A Inverse Teaching Assistant colon colon assists semicolon
Line 109. relationship Set open angled bracket Mark close angled bracket given In Inverse Mark colon colon given To semicolon
Line 110. close curly brace semicolon
Line 111. class Evaluation
Line 112. open parentheses extent Evaluations
Line 113. key open parentheses eval Date comma is Eval Of close parentheses close parentheses
Line 114. open curly brace
Line 115. forward slash asterisk define attributes asterisk forward slash
Line 116. attribute date eval Date semicolon
Line 117. attribute string rater Name semicolon
Line 118. attribute int rating semicolon
Line 119. forward slash asterisk define relationships asterisk forward slash
Line 120. relationship Faculty is Eval Of Inverse Faculty colon colon has Evaluation semicolon
Line 121. close curly brace semicolon
Line 122. class Mark
Line 123. open parentheses extent Grades close parentheses
Line 124. open curly brace
Line 125. forward slash asterisk define attributes asterisk forward slash
Line 126. attribute string grade semicolon
Line 127. forward slash asterisk define relationships asterisk forward slash
Line 128. relationship Class Section given To Inverse Class Section colon colon given In semicolon
Line 129. relationship Student given Student Inverse Student colon colon earned Grade semicolon
Line 130. close curly brace

Line 1. class Person
Line 2. open parentheses extent People
Line 3. key p I d close parentheses
Line 4. open curly brace
Line 5. forward slash asterisk define attributes asterisk forward slash
Line 6. attribute int p I d semicolon
Line 7. attribute string name semicolon
Line 8. attribute Struct A d d r open parentheses string street comma string city comma string state comma string zip close parentheses address semicolon
Line 9. attribute string phone semicolon
Line 10. attribute date birth Date semicolon
Line 11. forward slash asterisk define methods asterisk forward slash
Line 12. int find Age open parentheses close parentheses semicolon
Line 13. close curly brace semicolon
Line 14. class Student extends Person
Line 15. open parentheses extent Students close parentheses
Line 16. open curly brace
Line 17. forward slash asterisk define attributes asterisk forward slash
Line 18. attribute int credits semicolon
Line 19. attribute real open parentheses 3 comma 2 close parentheses g p a semicolon
Line 20. forward slash asterisk define relationships asterisk forward slash
Line 21. relationship Set open angled bracket Class Section close angled bracket takes Class Inverse Class Section colon colon has Student semicolon
Line 22. relationship Set open angled bracket Mark close angled bracket earned Grade Inverse Mark colon colon given Student semicolon
Line 23. relationship Faculty has Advisor Inverse Faculty colon colon advises semicolon
Line 24. forward slash asterisk define methods asterisk forward slash
Line 25. string get Status open parentheses close parentheses semicolon
Line 26. void add Credits open parentheses in int num Credits close parentheses semicolon
Line 27. close curly brace semicolon
Line 28. class Faculty extends Person
Line 29. open parentheses extent Fac close parentheses
Line 30. open curly brace
Line 31. forward slash asterisk define attributes asterisk forward slash
Line 32. attribute enum Faculty Rank open curly brace lecturer comma instructor comma assistant comma associate comma professor close curly brace
Line 33. rank semicolon
Line 34. attribute real open parentheses 8 comma 2 close parentheses salary semicolon
Line 35. forward slash asterisk define relationships asterisk forward slash
Line 36. relationship Department belongs To Inverse Department colon colon has Faculty semicolon
Line 37. relationship Set open angled bracket Class Section close angled bracket teaches Inverse Class Section colon colon has Teacher semicolon
Line 38. relationship Set open angled bracket Student close angled bracket advises Inverse Student colon colon has Advisor semicolon
Line 39. relationship Department chairs Inverse Department colon colon has Chair semicolon
Line 40. relationship Set open angled bracket Evaluation close angled bracket has Evaluation Inverse Evaluation colon colon is Eval Of semicolon
Line 41. forward slash asterisk define methods asterisk forward slash
Line 42. void give Raise open parentheses in float amount close parentheses raises open parentheses Salary out of range close parentheses semicolon
Line 43. forward slash asterisk raises an exception if salary is out of range asterisk forward slash
Line 44. close curly brace semicolon
Line 45. class Undergraduate extends Student
Line 46. open parentheses extent Undergrads close parentheses
Line 47. open curly brace
Line 48. forward slash asterisk define attributes asterisk forward slash
Line 49. attribute string major semicolon
Line 50. forward slash asterisk define methods asterisk forward slash
Line 51. void change Major open parentheses in string new Major close parentheses raises open parentheses Invalid major close parentheses semicolon
Line 52. close curly brace semicolon
Line 53. class Graduate extends Student
Line 54. open parentheses extent Grads close parentheses
Line 55. open curly brace
Line 56. forward slash asterisk define attributes asterisk forward slash
Line 57. attribute string program semicolon
Line 58. forward slash asterisk define methods asterisk forward slash
Line 59. string change Program open parentheses in string new Program close parentheses raises open parentheses Invalid program close parentheses semicolon
Line 60. close curly brace semicolon
Line 61. class Teaching Assistant extends Graduate
Line 62. open parentheses extent T A s close parentheses
Line 63. open curly brace
Line 64. forward slash asterisk define attributes asterisk forward slash
Line 65. attribute string funding Source semicolon
Line 66. attribute real open parentheses 7 comma 2 close parentheses annual Stipend semicolon
Line 67. forward slash asterisk define relationships asterisk forward slash
Line 68. relationship Class Section assists Inverse Class Section colon colon has T A semicolon
Line 69. close curly brace semicolon
Line 70. class Department
Line 71. open parentheses extent Departments
Line 72. key open parentheses dept Code comma dept Name close parentheses close parentheses
Line 73. open curly brace
Line 74. forward slash asterisk define attributes asterisk forward slash
Line 75. attribute string dept Code semicolon
Line 76. attribute string dept Name semicolon
Line 77. attribute string dept Office semicolon
Line 78. attribute string phone semicolon
Line 79. forward slash asterisk define relationships asterisk forward slash
Line 80. relationship Set open angled bracket Faculty close angled bracket has Faculty Inverse Faculty colon colon belongs To semicolon
Line 81. relationship Faculty has Chair Inverse Faculty colon colon chairs semicolon
Line 82. relationship Set open angled bracket Course close angled bracket offers Inverse Course colon colon is Offering semicolon
Line 83. close curly brace semicolon
Line 84. class Course
Line 85. open parentheses extent Courses
Line 86. key c No close parentheses
Line 87. open curly brace
Line 88. forward slash asterisk define attributes asterisk forward slash
Line 89. attribute string c No semicolon
Line 90. attribute string c Title semicolon
Line 91. attribute int credits semicolon
Line 92. attribute string description semicolon
Line 93. forward slash asterisk define relationships asterisk forward slash
Line 94. relationship Set open angled bracket Course close angled bracket has Prerequisite Inverse is Prereq Of semicolon
Line 95. relationship Set open angled bracket Course close angled bracket is Prereq Of Inverse has Prerequisite semicolon
Line 96. relationship Department is Offering Inverse Department colon colon offers semicolon
Line 97. close curly brace semicolon
Line 98. class Class Section extends Course
Line 99. open parentheses extent Sections close parentheses
Line 100. open curly brace
Line 101. forward slash asterisk define attributes asterisk forward slash
Line 102. attribute string section Code semicolon
Line 103. attribute string schedule semicolon
Line 104. attribute string room semicolon
Line 105. forward slash asterisk define relationships asterisk forward slash
Line 106. relationship Set open angled bracket Student close angled bracket has Student Inverse Student colon colon takes Class semicolon
Line 107. relationship Faculty has Teacher Inverse Faculty colon colon teaches semicolon
Line 108. relationship Teaching Assistant has T A Inverse Teaching Assistant colon colon assists semicolon
Line 109. relationship Set open angled bracket Mark close angled bracket given In Inverse Mark colon colon given To semicolon
Line 110. close curly brace semicolon
Line 111. class Evaluation
Line 112. open parentheses extent Evaluations
Line 113. key open parentheses eval Date comma is Eval Of close parentheses close parentheses
Line 114. open curly brace
Line 115. forward slash asterisk define attributes asterisk forward slash
Line 116. attribute date eval Date semicolon
Line 117. attribute string rater Name semicolon
Line 118. attribute int rating semicolon
Line 119. forward slash asterisk define relationships asterisk forward slash
Line 120. relationship Faculty is Eval Of Inverse Faculty colon colon has Evaluation semicolon
Line 121. close curly brace semicolon
Line 122. class Mark
Line 123. open parentheses extent Grades close parentheses
Line 124. open curly brace
Line 125. forward slash asterisk define attributes asterisk forward slash
Line 126. attribute string grade semicolon
Line 127. forward slash asterisk define relationships asterisk forward slash
Line 128. relationship Class Section given To Inverse Class Section colon colon given In semicolon
Line 129. relationship Student given Student Inverse Student colon colon earned Grade semicolon
Line 130. close curly brace
Line 1. class Person
Line 2. open parentheses extent People
Line 3. key p I d close parentheses
Line 4. open curly brace
Line 5. forward slash asterisk define attributes asterisk forward slash
Line 6. attribute int p I d semicolon
Line 7. attribute string name semicolon
Line 8. attribute Struct A d d r open parentheses string street comma string city comma string state comma string zip close parentheses address semicolon
Line 9. attribute string phone semicolon
Line 10. attribute date birth Date semicolon
Line 11. forward slash asterisk define methods asterisk forward slash
Line 12. int find Age open parentheses close parentheses semicolon
Line 13. close curly brace semicolon
Line 14. class Student extends Person
Line 15. open parentheses extent Students close parentheses
Line 16. open curly brace
Line 17. forward slash asterisk define attributes asterisk forward slash
Line 18. attribute int credits semicolon
Line 19. attribute real open parentheses 3 comma 2 close parentheses g p a semicolon
Line 20. forward slash asterisk define relationships asterisk forward slash
Line 21. relationship Set open angled bracket Class Section close angled bracket takes Class Inverse Class Section colon colon has Student semicolon
Line 22. relationship Set open angled bracket Mark close angled bracket earned Grade Inverse Mark colon colon given Student semicolon
Line 23. relationship Faculty has Advisor Inverse Faculty colon colon advises semicolon
Line 24. forward slash asterisk define methods asterisk forward slash
Line 25. string get Status open parentheses close parentheses semicolon
Line 26. void add Credits open parentheses in int num Credits close parentheses semicolon
Line 27. close curly brace semicolon
Line 28. class Faculty extends Person
Line 29. open parentheses extent Fac close parentheses
Line 30. open curly brace
Line 31. forward slash asterisk define attributes asterisk forward slash
Line 32. attribute enum Faculty Rank open curly brace lecturer comma instructor comma assistant comma associate comma professor close curly brace
Line 33. rank semicolon
Line 34. attribute real open parentheses 8 comma 2 close parentheses salary semicolon
Line 35. forward slash asterisk define relationships asterisk forward slash
Line 36. relationship Department belongs To Inverse Department colon colon has Faculty semicolon
Line 37. relationship Set open angled bracket Class Section close angled bracket teaches Inverse Class Section colon colon has Teacher semicolon
Line 38. relationship Set open angled bracket Student close angled bracket advises Inverse Student colon colon has Advisor semicolon
Line 39. relationship Department chairs Inverse Department colon colon has Chair semicolon
Line 40. relationship Set open angled bracket Evaluation close angled bracket has Evaluation Inverse Evaluation colon colon is Eval Of semicolon
Line 41. forward slash asterisk define methods asterisk forward slash
Line 42. void give Raise open parentheses in float amount close parentheses raises open parentheses Salary out of range close parentheses semicolon
Line 43. forward slash asterisk raises an exception if salary is out of range asterisk forward slash
Line 44. close curly brace semicolon
Line 45. class Undergraduate extends Student
Line 46. open parentheses extent Undergrads close parentheses
Line 47. open curly brace
Line 48. forward slash asterisk define attributes asterisk forward slash
Line 49. attribute string major semicolon
Line 50. forward slash asterisk define methods asterisk forward slash
Line 51. void change Major open parentheses in string new Major close parentheses raises open parentheses Invalid major close parentheses semicolon
Line 52. close curly brace semicolon
Line 53. class Graduate extends Student
Line 54. open parentheses extent Grads close parentheses
Line 55. open curly brace
Line 56. forward slash asterisk define attributes asterisk forward slash
Line 57. attribute string program semicolon
Line 58. forward slash asterisk define methods asterisk forward slash
Line 59. string change Program open parentheses in string new Program close parentheses raises open parentheses Invalid program close parentheses semicolon
Line 60. close curly brace semicolon
Line 61. class Teaching Assistant extends Graduate
Line 62. open parentheses extent T A s close parentheses
Line 63. open curly brace
Line 64. forward slash asterisk define attributes asterisk forward slash
Line 65. attribute string funding Source semicolon
Line 66. attribute real open parentheses 7 comma 2 close parentheses annual Stipend semicolon
Line 67. forward slash asterisk define relationships asterisk forward slash
Line 68. relationship Class Section assists Inverse Class Section colon colon has T A semicolon
Line 69. close curly brace semicolon
Line 70. class Department
Line 71. open parentheses extent Departments
Line 72. key open parentheses dept Code comma dept Name close parentheses close parentheses
Line 73. open curly brace
Line 74. forward slash asterisk define attributes asterisk forward slash
Line 75. attribute string dept Code semicolon
Line 76. attribute string dept Name semicolon
Line 77. attribute string dept Office semicolon
Line 78. attribute string phone semicolon
Line 79. forward slash asterisk define relationships asterisk forward slash
Line 80. relationship Set open angled bracket Faculty close angled bracket has Faculty Inverse Faculty colon colon belongs To semicolon
Line 81. relationship Faculty has Chair Inverse Faculty colon colon chairs semicolon
Line 82. relationship Set open angled bracket Course close angled bracket offers Inverse Course colon colon is Offering semicolon
Line 83. close curly brace semicolon
Line 84. class Course
Line 85. open parentheses extent Courses
Line 86. key c No close parentheses
Line 87. open curly brace
Line 88. forward slash asterisk define attributes asterisk forward slash
Line 89. attribute string c No semicolon
Line 90. attribute string c Title semicolon
Line 91. attribute int credits semicolon
Line 92. attribute string description semicolon
Line 93. forward slash asterisk define relationships asterisk forward slash
Line 94. relationship Set open angled bracket Course close angled bracket has Prerequisite Inverse is Prereq Of semicolon
Line 95. relationship Set open angled bracket Course close angled bracket is Prereq Of Inverse has Prerequisite semicolon
Line 96. relationship Department is Offering Inverse Department colon colon offers semicolon
Line 97. close curly brace semicolon
Line 98. class Class Section extends Course
Line 99. open parentheses extent Sections close parentheses
Line 100. open curly brace
Line 101. forward slash asterisk define attributes asterisk forward slash
Line 102. attribute string section Code semicolon
Line 103. attribute string schedule semicolon
Line 104. attribute string room semicolon
Line 105. forward slash asterisk define relationships asterisk forward slash
Line 106. relationship Set open angled bracket Student close angled bracket has Student Inverse Student colon colon takes Class semicolon
Line 107. relationship Faculty has Teacher Inverse Faculty colon colon teaches semicolon
Line 108. relationship Teaching Assistant has T A Inverse Teaching Assistant colon colon assists semicolon
Line 109. relationship Set open angled bracket Mark close angled bracket given In Inverse Mark colon colon given To semicolon
Line 110. close curly brace semicolon
Line 111. class Evaluation
Line 112. open parentheses extent Evaluations
Line 113. key open parentheses eval Date comma is Eval Of close parentheses close parentheses
Line 114. open curly brace
Line 115. forward slash asterisk define attributes asterisk forward slash
Line 116. attribute date eval Date semicolon
Line 117. attribute string rater Name semicolon
Line 118. attribute int rating semicolon
Line 119. forward slash asterisk define relationships asterisk forward slash
Line 120. relationship Faculty is Eval Of Inverse Faculty colon colon has Evaluation semicolon
Line 121. close curly brace semicolon
Line 122. class Mark
Line 123. open parentheses extent Grades close parentheses
Line 124. open curly brace
Line 125. forward slash asterisk define attributes asterisk forward slash
Line 126. attribute string grade semicolon
Line 127. forward slash asterisk define relationships asterisk forward slash
Line 128. relationship Class Section given To Inverse Class Section colon colon given In semicolon
Line 129. relationship Student given Student Inverse Student colon colon earned Grade semicolon
Line 130. close curly brace

FIGURE 9.6 ODL Definition for the University Schema

9.4.1 Class Declarations

Each class declaration begins with the keyword class, the name of the class, an optional extent and key declaration in parentheses, and a list of attributes, methods, and relationships enclosed in curly brackets.

9.4.2 Extent

The extent of a class can be thought of as the set of object instances for that class that are stored in the database at a given time. Using terms introduced earlier, the class definition is part of the intension of the database, while the extent is part of the extension of the database. In ER terms, the class is like the entity type, and the extent is the set of entity instances. It is good practice to choose a name for the extent that is slightly different from the name of the class. For the Person class, we called the extent People. The parentheses can also contain the name of the key, which we discuss in a later section.

9.4.3 Attributes

The attributes for a class are listed, preceded by their datatypes, within curly brackets. A wide variety of types are permitted in ODL, including simple types and more complex types that can be built from them.

Atomic types include integer, float, character, string, Boolean, and enumerated types. Enumerated types are identified by the keyword enum, the user-defined name of the type, a list of literals for the type within curly braces, and the name of the attribute with that type. For example, we made attribute rank in Faculty have an enumerated type called FacultyRank. We can also have structured types, identified by the keyword Struct, the name of the type, and parentheses containing each attribute with its data type. In the Person class definition, Addr is a structured type that we have used for the attribute address. Because we defined the type, we can use it again for other classes, but we must identify the class it was defined in, using the form Person::Addr, which is called the scoped name and consists of the class name, a double colon, and the structure name. This scoped form is used to refer to any property in a different class. Besides Struct, there are type constructors for five collection types, namely Set, List, Array, Bag, and Dictionary.

9.4.4 Relationships

Relationships represent connections between object instances. For example, faculty members relate to class sections because they teach them, students relate to classes that they take, departments relate to faculty who are employed in them, and so on. The OO model represents these connections using references. In ODL, the description of a relationship implies that the system stores and maintains such references. For example, there is a relationship called takesClass defined for the Student class in the line

relationship Set open angled bracket Class Section close angled bracket takes Class dot, dot, dot.

which tells us that each Student instance can contain a set of references, called takesClass, to ClassSection instances. Typically, the references are simply the OIDs of the related objects. The keyword Set shows that this is a “many” relationship for each student; that is, a Student instance can be related to a set of ClassSection instances, not just one.

Given a specific Student instance, we can use the takesClass relationship to find out what classes the student is taking. We also expect to turn the query around and, given a ClassSection instance, ask what students are in the class. We see that there is such an inverse relationship, hasStudent, defined for ClassSection. The phrase

Inverse Class Section colon colon has Student semicolon.

which appears on the same line as the takesClass relationship definition, means that each ClassSection object contains references to the corresponding Student instances. We note that in addition to specifying in the Student class that the inverse exists, we also specify this relationship in the ClassSection class in this line

Relationship Set open angled bracket Student close angled bracket has Student Inverse Student colon colon takes Class semicolon.

The connection between takesClass and hasStudent is that if a class appears in the takesClass set of references for a student, that same student should appear in the hasStudent set of references for the class. These two relationships are therefore inverses of each other, as indicated. Note that when we identify the inverse relationship, we normally use the scoped form for its name

Inverse class Name colon colon relationship Name semicolon.

because the inverse relationship is usually in another class definition.

In ODL, a relationship is not required to have an inverse. A relationship without an inverse is described as unidirectional, while a relationship with an inverse is bidirectional. A relationship also has cardinality, which can be one-to-one, one-to-many, many-to-one, or many-to-many. The bidirectional Student-ClassSection relationship is many-to-many in both directions, and both relationship specifications include a set of references. If a relationship is one-to-many, as in the relationship between Department and Faculty, the class on the “one” side, Department, defines the relationship as a set. In the Department definition, we have the relationship Set<Faculty> because each Department instance has references to many Faculty instances as shown in the line

Relationship Set open angled bracket Faculty close angled bracket has Faculty Inverse Faculty colon colon belongs To semicolon.

However, the relationship on the Faculty side

Relationship Department belongs To Inverse Department colon colon has Faculty semicolon.

specifies just Department (not Set<Department>) because a faculty record refers to only one department.

9.4.5 Methods

Method declarations in ODL specify the signature, which consists of the return type, the name of the method, and the names and types of parameters. Each parameter also has a mode that is identified as IN, OUT, or IN OUT, depending on whether the parameter is input, output, or both. In ODL, classes have automatic get() and set() methods for each attribute, so we need not list these unless we wish to override them. There are also other automatic methods for the manipulation of collections, such as sets, bags, and lists. Class member methods are applied to an instance of the class, which is referred to as self in the code for the method. The actual code for the method is not part of the ODL but is written in one of the host languages.

9.4.6 Classes and Inheritance

A subclass is identified by the keyword extends and the name of the superclass following the subclass name. The subclass inherits all the attributes, relationships, and methods of the superclass, and it can have some additional properties of its own that appear in the definition. For example, in Figure 9.6, Faculty extends Person, so it inherits pId, name, address, phone, birthdate, and findAge() from Person but adds some additional properties. If the subclass has more than one superclass, we add a colon and the name of the second superclass immediately after the name of the first superclass. As discussed earlier, different systems implement this feature in their own ways, if at all.

9.4.7 n-ary Relationships and M:N Relationships with Attributes

Relationships in ODL are binary, but if we must model a ternary or higher-order relationship, we can do so by creating a class for the relationship. The class definition would include three or more relationships that connect the new class to the originally related classes. For example, in a different class diagram we could have a ternary relationship connecting courses, instructors, and textbooks, shown in Chapter 3, Figure 3.6, which we might call BookOrder. For this example, we assume that the same course can be taught by different professors who may choose to use different textbooks. In the OO model, we would define the class for the BookOrder relationship, as shown in the following sketch:

Line 1. Class Book Order open curly brace.
Line 2. Relationship Faculty teacher Inverse Faculty colon colon adopts Text semicolon.
Line 3. Relationship Text Book book For Inverse Book colon colon used By semicolon.
Line 4. Relationship Course uses Inverse Course colon colon uses Text semicolon.

If the relationship has any descriptive attributes, they are listed as well. The inverse relationships must be included in the corresponding Faculty, TextBook, and Course class definitions. Note that this technique is similar to the way we treated higher-order relationships in the relational model, where we created tables for such relationships.

Binary many-to-many relationships with descriptive attributes cannot be handled by the usual solution of making the relationship a set in both directions, because that leaves no place for descriptive attributes. Referring to the UML diagram in Figure 9.5, we see that grade is an example of a descriptive attribute. We use the same solution as for n-ary relationships, setting up a class for the relationship. We place the descriptive attributes as attributes of the new class, and we define two one-to-many relationships between the two original classes and the new class. We have done this in Figure 9.6 by defining the class Mark. Note that we also kept the many-to-many relationship between Student and ClassSection that represents enrollment in the section by defining set relationships in both. This relationship did not require a new class definition because it has no descriptive attributes.

9.4.8 Keys

Keys are optional in ODL because the unique OID automatically given to each object instance allows the system to tell instances apart. However, the designer may choose to identify any candidate keys as well. This is done at the beginning of the class declaration within the same parentheses as the extent declaration. A key can be a single attribute or a composite, which is identified by placing parentheses around the names of component attributes. For example, we could have written

Line 1. Class Faculty extends Person.
Line 2. Open parentheses extent F a c.
Line 3. Key p I d, comma, open parentheses name comma belongs To close parentheses close parentheses.

This indicates that pId is a key, and the combination of name and belongsTo is a key. Keys are not restricted to attributes, as shown in the composite key definition. We can list a relationship (such as belongsTo) or even a method as a key, provided it gives us unique values.

Weak entity sets can often be represented as subclasses in which the relationship to the superclass is part of the key, with the discriminator as another part. For example, for the weak entity set Evaluation, we wrote

Line 1. Class Evaluation.
Line 2. Open parentheses extent Evaluations.
Line 3. Key open parentheses eval Date comma is Eval Of close parentheses close parentheses.
Line 4. Open curly brace dot, dot, dot.
Line 5. Relationship Faculty is Eval Of Inverse Faculty colon colon has Evaluation semicolon.
Line 6. Dot, dot, dot.
Line 7. Close curly brace.

This means the composite key consists of the date of the evaluation and the identity of the related faculty member.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.150.203