9.3 OO Data Modeling Using Unified Modeling Language (UML)

Entity-relationship (ER) diagrams are not well suited to representing objects because they do not allow representation of methods. The OMG defines and maintains standards for the Unified Modeling Language (UML), which was developed as a standard for software models. UML class diagrams allow us to express OO database concepts more naturally than standard ER diagrams. FIGURE 9.5 shows a UML class diagram for part of the revised University database, in which we show many of the features of such diagrams. The choices made in constructing this diagram are intended to demonstrate different features of the diagramming notation, and do not represent the only, or necessarily the best, possible model for the example.

The 10 classes shown in the diagram are labeled open angled bracket open angled bracket persistent close angled bracket close angled bracket Person, open angled bracket open angled bracket persistent close angled bracket close angled bracket Department, open angled bracket open angled bracket persistent close angled bracket close angled bracket Student, open angled bracket open angled bracket persistent close angled bracket close angled bracket Faculty, open angled bracket open angled bracket persistent close angled bracket close angled bracket course, open angled bracket open angled bracket persistent close angled bracket close angled bracket Undergraduate, open angled bracket open angled bracket persistent close angled bracket close angled bracket Graduate, open angled bracket open angled bracket persistent close angled bracket close angled bracket Teaching Assistant, open angled bracket open angled bracket persistent close angled bracket close angled bracket Evaluation, open angled bracket open angled bracket persistent close angled bracket close angled bracket Class Section. The attributes of the Person class are p I d, name, address, phone, and birthdate. The method of the Person class is find Age open parentheses close parentheses. The attributes of the Department class are dept Code, dept Name, dept Office, and phone. The Department class does not have any methods. The attributes of the Student class are credits and g p a. The methods of the Student class are get Status open parentheses close parentheses, and add Credits open parentheses close parentheses. The attributes of the Faculty class are rank and salary. The method of the Faculty class is give Raise open parentheses close parentheses. The attributes of the Course class are c No, c Title, credits, and description. The method of the Course class is change Desc open parentheses close parentheses. The attribute of the Undergraduate class is major and change Major open parentheses close parentheses. The attribute of the Graduate class is program and the method is change Program open parentheses close parentheses. The attributes of the Teaching Assistant class are funding Source and annual Stipend. The attributes of the Evaluation class are rater Name and rating. The attributes of the Class Section are section Code, schedule and room. The Evaluation and Class Section classes do not have methods. Arrows are drawn from the Student and Faculty classes to the Person Class. The caption beside the arrow is open parentheses overlapping, optional close parentheses. A double headed arrow is drawn between Faculty and Department classes. The caption beside Faculty class is 0 dot dot asterisk, has Faculty. The caption beside the Department class is 1, belongs To. Another double headed arrow is drawn between the Faculty and Department classes. The caption beside the Faculty class is 1, has Chair. The caption beside the Department class is 0 dot dot 1 chairs. A double headed arrow is drawn between the Course and Department classes. The caption beside the Department Class is 1, is Offering. The caption beside the Course class is 0 dot dot asterisk, offers. A double headed arrow is drawn between the top and bottom of the Course class. The caption beside the arrow are 0 dot dot asterisk, is Pre req Of, and 0 dot dot asterisk has Prerequisite. A double headed arrow is drawn between the Student and Faculty classes. The caption beside the Student class is 0 dot dot asterisk advises and the caption beside the Faculty class is 1, has Advisor. A double headed arrow is drawn between the Student and Class Section classes. The caption beside the Student class is 0 dot dot asterisk has Student. The caption beside the Class Section class is 0 dot dot asterisk takes Class. Another double headed arrow is drawn between the Student and Class Section classes via a block labeled grade. The caption beside the Student class is 0 dot dot asterisk, given Student. The caption beside the Class Section class is 0 dot dot asterisk, earned Grade. A double headed arrow is drawn between the Faculty and Class Section classes. The caption beside the Faculty class is 1, has Teacher. The caption beside the Class Section class is 0 dot dot asterisk, teaches. A line with a diamond at its end is drawn from the Class Section Class to the Course Class. The caption beside the Class Section class is 0 dot dot asterisk, has Section. The caption beside the Course class is 1, is Section. A double headed arrow is drawn between the Teaching Assistant class and Class Section class. The caption beside the Teaching Assistant class is 0 dot dot 1, has T A. The caption beside the Class Section class is 0 dot dot 1, assists. An arrow is drawn from the Teaching Assistant class to the Graduate Class. Arrows are drawn from the Undergraduate and Graduate classes to the Student class. The caption beside the Student class is open parentheses disjoint comma mandatory close parentheses.

FIGURE 9.5 A UML Class Diagram

In a UML class diagram, rectangles represent classes. Class rectangles are subdivided into three sections: the top one for the class name, the middle for the attributes, and the bottom for the methods. The string in guillements (<<>>) above the class name is called a stereotype. The <<persistent>> stereotype indicates that the class is persistent, which means it maps to a database and its objects will persist in storage after the program terminates. Generalization hierarchies are represented by lines connecting the subclasses to the superclass, with a triangle pointing toward the superclass.

In Figure 9.5, Person is specialized into Student and Faculty, and Student is specialized into Undergraduate and Graduate. Graduate has a subclass, TeachingAssistant. Note that for this example, TeachingAssistant is not a subclass of Faculty. A filled generalization triangle represents overlapping subclasses, which means an object can belong to both subclasses, while a blank (outline-only) triangle represents disjoint ones. The diagram shows that a Person can be both a Student and a Faculty member, but a Student cannot be both Undergraduate and Graduate. If each member of the superclass must belong to a subclass, we describe the specialization as mandatory, as opposed to optional. Specialization constraints can be written on the line near the triangle, enclosed in curly brackets. For example, we write {overlapping, optional} for the specialization of Person into Student and Faculty, which shows that not every Person has to be a Student or a Faculty but some could be both, and {disjoint, mandatory} for Student into Undergraduate and Graduate to show that every Student must be either Undergraduate or Graduate but not both.

Relationships between classes are also shown by lines. In UML, we distinguish between an association, which is either a unidirectional or bidirectional relationship between classes, and aggregation, which is a type of relationship that connects a whole to its parts. Associations, or binary connections between classes, are represented by lines connecting the class rectangles. Several associations, such as the one connecting Department and Course, are shown in Figure 9.5. The name of the association may optionally appear on the line. Any descriptive attribute of the relationship is shown in a box connected to the association line by a dotted line, as shown in the grade attribute of the association that connects Student to ClassSection.

Role names can also appear on association lines if they are needed for clarity, but their placement is opposite to that in an ER diagram, appearing at the head (arrow) of the directed line from a class to the class it relates to. For one of the associations between Department and Faculty, we have used role names hasChair (from Department to Faculty) and chairs (from Faculty to Department) to show that it connects the chairperson with the department.

Aggregation is a special type of relationship that connects a whole to its parts. If the phrase describing the relationship of one class to another is that it “is part of” the other, and the class is clearly subordinate to the other, then aggregation is the better representation of the relationship. We represented the relationship between Course and ClassSection as an aggregation. The aggregation is represented by a line with a diamond on the side of the class that is the aggregate. If the aggregation is not given a name, the aggregation line is interpreted to mean “has.”

Participation constraints and cardinality for both association and aggregation relationships are specified using min..max notation. Each relationship line connecting classes has a pair of integers, min..max, along with the optional role name. The first integer of the pair, min, specifies the least number of relationship instances in which an object must participate. A min of 0 means that there may be objects that do not participate in instances of the relationship, so the participation is partial. If min is 1 or more, the participation is total, meaning that each object must participate in at least one instance of the relationship. The value of max is the greatest number of relationship instances an object can participate in. This value could be 1, N, or * (to represent many), or some constant integer, such as 10. If both min and max have a value of 1, we simply write the single integer 1 instead of 1..1. In UML diagrams, we call these multiplicity indicators, and we place them at the head of the arrow for the relationship. For example, the 0..* with the label offers at the head of the arrow going from Department to Course indicates that a Department can offer no courses or many courses, while the 1 with the label isOffering at the head of the arrow from Course to Department means that a Course is an offering from exactly one Department.

In Chapter 3, we saw that in extended entity-relationship (EER) diagrams, parentheses are used around the values, which are separated by a comma, and the constraints are placed between the entity rectangle and the relationship diamond, essentially placing them opposite their placement in UML (shown in Chapter 3.) The multiplicity indicator placement in EER diagrams is sometimes described as “look here,” while the placement in UML diagrams is “look there.”

Recursive relationships between members of the same class, called reflexive associations or reflexive aggregations, are shown by an association line or aggregation line going from a class back into itself. The relationship that connects courses and their prerequisites is a reflexive association. Role names appear on the line, with multiplicity indicators at each end. On the diagram we show that a Course may have zero to many prerequisites and that a Course may be a prerequisite for zero to many other courses.

Weak entities can be represented by a box attached to the associated strong owner entity, with the discriminator (partial key) appearing in a box beneath the owner’s class rectangle. Figure 9.5 illustrates Evaluation as a weak entity, dependent on Faculty. For this example, we assume the same faculty member is never evaluated twice on the same day, so we use evalDate as the discriminator.

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

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