You are on page 1of 10

CHAPTER 13

Overview: Object-Oriented
Data Modeling

LEARNING OBJECTIVES
After studying this chapter, you should be able to:
■ Concisely define each of the following key terms: class, object, state, behavior, class

diagram, object diagram, operation, encapsulation, constructor operation, query


operation, update operation, class-scope operation, association, association role,
multiplicity, association class, abstract class, concrete class, class-scope attribute,
abstract operation, method, polymorphism, overriding, multiple classification,
aggregation, and composition.
■ Describe the activities in the different phases of the object-oriented development life

cycle.
■ State the advantages of object-oriented modeling vis-à-vis structured approaches.

■ Compare the object-oriented model with the E-R and EER models.

■ Model a real-world domain by using a Unified Modeling Language (UML) class

diagram.
■ Provide a snapshot of the detailed state of a system at a point in time, using a UML

object diagram.
■ Recognize when to use generalization, aggregation, and composition relationships.

■ Specify different types of business rules in a class diagram.

OVERVIEW
In Chapters 2 and 3, you learned about data modeling using the E-R and EER models.
In those chapters, you discovered how to model the data needs of an organization using
entities, attributes, and a wide variety of relationships. In this chapter, you will be intro-
duced to the object-oriented model, which is becoming increasingly popular because of
its ability to thoroughly represent complex relationships, as well as to represent data
and system behavior in a consistent, integrated notation. Fortunately, most of the con-
cepts you learned in those chapters correspond to concepts in object-oriented modeling.
The object-oriented approach offers even more expressive power than the EER model.

A complete version of this chapter is available on the textbook’s Web site


(www.pearsonhighered.com/hoffer). The following is a brief overview.

518
Chapter 13 • Overview: Object-Oriented Data Modeling 519

An object-oriented model is built around objects, just as the E-R model is built
around entities. An object encapsulates both data and behavior, implying that we can
use the object-oriented approach not only for data modeling, but also to model sys-
tem behavior. To thoroughly represent any real-world system, you need to model both
the data and the processes and behavior that act on the data (recall the discussion in
Chapter 1 about information planning objects). By allowing you to capture them to-
gether within a common representation, and by offering benefits such as inheritance and
code reuse, the object-oriented modeling approach provides a powerful environment
for developing complex systems.
Coad and Yourdon (1991) identify several motivations and benefits of object-
oriented modeling: the ability to tackle more challenging problem domains; improved
communication among the users, analysts, designers, and programmers; increased con-
sistency among analysis, design, and programming activities; explicit representation of
commonality among system components; robustness of systems; reusability of analy-
sis, design, and programming results; and increased consistency among all the models
developed during object-oriented analysis, design, and programming.
In this chapter, we present object-oriented data modeling as a high-level concep-
tual activity. As you will learn in Chapter 14, a good conceptual model is invaluable for
designing and implementing an object-oriented application that uses a relational data-
base for providing persistence for the objects.

Unified Modeling Language


Unified Modeling Language (UML) is a set of graphical notations backed by a com-
mon metamodel that is widely used both for business modeling and for specifying, de-
signing, and implementing software systems artifacts. To represent a complex system
effectively, the model you develop must consist of a set of independent views or per-
spectives. UML allows you to represent multiple perspectives of a system by provid-
ing different types of graphical diagrams, such as the use-case diagram, class diagram,
state diagram, sequence diagram, component diagram, and deployment diagram. If
these diagrams are used correctly together in the context of a well-defined modeling
process, UML allows you to analyze, design, and implement a system based on one
consistent conceptual model.
Because this text is about databases, we will describe only the class diagram,
which is one of the static diagrams in UML, addressing primarily structural charac-
teristics of the domain of interest. The class diagram allows us also to capture the re-
sponsibilities that classes can perform, without any specifics of the behaviors. We will
not describe the other diagram types because they provide perspectives that are not
directly related to database systems. Keep in mind that a database system is usually
part of an overall system, whose underlying model should encompass all the differ-
ent perspectives. For a discussion of other UML diagrams, see Hoffer et al. (2011) and
George et al. (2007). It is important to note that the UML class diagrams can be used
for multiple purposes at various stages of the life cycle model. Class
An entity that has a well-defined
Object-Oriented Data Modeling role in the application domain
about which the organization
A class is an entity type that has a well-defined role in the application domain about which wishes to maintain state, behavior,
the organization wishes to maintain state, behavior, and identity. A class is a concept, and identity.
an abstraction, or a thing that makes sense and matters in an application context (Blaha Object
and Rumbaugh, 2005). A class could represent a tangible or visible entity type (e.g.,
An instance of a class that
a person, place, or thing); it could be a concept or an event (e.g., Department, Performance, encapsulates data and behavior.
Marriage, Registration, etc.); or it could be an artifact of the design process (e.g., User
Interface, Controller, Scheduler). An object is an instance of a class (e.g., a particular State
person, place, or thing) that encapsulates the data and behavior we need to maintain An object’s properties (attributes
about that object. A class of objects shares a common set of attributes and behaviors. and relationships) and the values
those properties have.
The state of an object encompasses its properties (attributes and relationships)
and the values those properties have, and its behavior represents how an object acts Behavior
and reacts (Booch, 1994). Thus, an object’s state is determined by its attribute values and The way in which an object acts
links to other objects. An object’s behavior depends on its state and the operation being and reacts.
520 Part V • Advanced Database Topics

performed. An operation is simply an action that one object performs in order to give a
response to a request. You can think of an operation as a service provided by an object
(supplier) to its clients. A client sends a message to a supplier, which delivers the de-
sired service by executing the corresponding operation.
Consider an example of the Student class and a particular object in this class, Mary
Jones. The state of this object is characterized by its attributes, say, name, date of birth,
year, address, and phone, and the values these attributes currently have. For example,
name is “Mary Jones,” year is “junior,” and so on. The object’s behavior is expressed
through operations such as calcGpa, which is used to calculate a student’s current grade
point average. The Mary Jones object, therefore, packages its state and its behavior to-
gether. Every object has a persistent identity; that is, no two objects are the same, and an
object maintains its own identity over its life. For example, if Mary Jones gets married
and the values of the attributes name, address, and phone change for her, she will still
be represented by the same object.
You can depict the classes graphically in a class diagram as in Figure 13-2a. (Note:
figure numbers are not continuous in this overview because only selected figures from
Class diagram the complete chapter on the textbook’s Web site are included in this overview.) A class
A diagram that shows the static diagram shows the static structure of an object-oriented model: the object classes, their
structure of an object-oriented internal structure, and the relationships in which they participate. The figure shows two
model: the object classes, their classes, Student and Course, along with their attributes and operations. All students have
internal structure, and the
relationships in which they
in common the properties of name, dateOfBirth, year, address, and phone. They also exhibit
participate. common behavior by sharing the calcAge, calcGpa, and registerFor(course) operations.
An operation, such as calcGpa in Student (see Figure 13-2a), is a function or a ser-
Operation vice that is provided by all the instances of a class. Typically, other objects can access or
A function or a service that is manipulate the information stored in an object only through such operations. The opera-
provided by all the instances of a tions, therefore, provide an external interface to a class; the interface presents the out-
class.
side view of the class without showing its internal structure or how its operations are
Encapsulation implemented. This technique of hiding the internal implementation details of an object
The technique of hiding the
from its external view is known as encapsulation, or information hiding. So although
internal implementation details of we provide the abstraction of the behavior common to all instances of a class in its inter-
an object from its external view. face, we hide within the class its structure and the secrets of the desired behavior.

FIGURE 13-2 UML class and


object diagrams
(a) Class diagram showing
two classes Student Class name Course

name crseCode
dateOfBirth crseTitle
year List of creditHrs
attributes
address
phone

calcAge( ) enrollment( )
List of
calcGpa( ) operations
registerFor(course)

(b) Object diagram with two


instances

Mary Jones: Student :Course

name = Mary Jones crseCode = MIS385


dateOfBirth = 4/15/88 crseTitle = Database Mgmt
year = junior creditHrs = 3
...
Chapter 13 • Overview: Object-Oriented Data Modeling 521

Parallel to the definition of a relationship for the E-R model, an association is a Association
named relationship between or among instances of object classes. In Figure 13-3, we use A named relationship between or
examples from Figure 3-12 to illustrate how the object-oriented model can be used to among object classes.
represent association relationships of different degrees. The end of an association where
it connects to a class is called an association role (Rumbaugh et al., 2004). A role may Association role
be explicitly named with a label near the end of an association (see the “manager” role The end of an association, where it
in Figure 13-3a). connects to a class.
Each role has a multiplicity, which indicates the number of objects that partici- Multiplicity
pate in a given relationship. In a class diagram, a multiplicity specification is shown
A specification that indicates how
as a text string representing an interval (or intervals) of integers in the following many objects participate in a given
format: relationship.

lower-bound..upper-bound

In addition to integer values, the upper bound of a multiplicity can be a star


character (*), which denotes an infinite upper bound. If a single integer value is speci-
fied, it means that the range includes only that value.

FIGURE 13-3 Examples of


association relationships
of different degrees
0..1 * (a) Unary relationships

Person Is Married To Employee Manages

0..1 0..1 manager

(b) Binary relationships

0..1 Is Assigned 0..1 Parking


Employee
Place
One-to-one

Product 1 Contains 1..*


Product
Line
One-to-many

* Registers For *
Student Course
Many-to-many

(c) Ternary relationship

Part

Vendor * Supplies * Warehouse


522 Part V • Advanced Database Topics

FIGURE 13-6 Association class


and link object
(a) Class diagram showing * *
tutor
association classes Student Course
*

pupil *
Tutors

Registration Computer Account

term Issues acctID


grade * 0..1 password
beginDate checkEligibility() serverSpace
numberOfHrs

(b) Object diagram showing


link objects
:Registration

term = Fall2010
grade = W
MKT350

Mary Jones

MIS385

:Registration :Computer Account

term = Fall2010 acctID = jones385


password = 12345
serverSpace = 10

When an association has attributes or operations of its own, or when it participates


Association class in relationships with other classes, it is useful to model the association as an association
An association that has attributes class (just as we used an “associative entity” in Chapter 3). For example, in Figure 13-6a,
or operations of its own or that the attributes term and grade and the operation checkEligibility really belong to the
participates in relationships with many-to-many association between Student and Course.
other classes.
You have the option of showing the name of an association class on the associa-
tion path or the class symbol or both. When an association has only attributes but does
not have any operations or does not participate in other associations, the recommended
option is to show the name on the association path, but to omit it from the association
class symbol, to emphasize its “association nature” (UML Notation Guide, 2003). That is
how we have shown the Tutors association. On the other hand, we have displayed the
name of the Registration association—which has two attributes and one operation of its
own, as well as an association called Issues with Computer Account—within the class
rectangle to emphasize its “class nature.”
You were introduced to generalization and specialization in Chapter 3. In object data
modeling, the classes that are generalized are called subclasses, and the class they are
generalized into is called a superclass, in perfect correspondence to subtypes and super-
types for EER diagramming.
Consider the example shown in Figure 13-9a (see Figure 3-8 for the corre-
sponding EER diagram). A generalization path is shown as a solid line from the
subclass to the superclass, with a hollow triangle at the end of, and pointing toward,
the superclass. You can show a group of generalization paths for a given superclass as a
tree with multiple branches connecting the individual subclasses, and a shared segment
Chapter 13 • Overview: Object-Oriented Data Modeling 523

FIGURE 13-8 Derived attribute,


association, and role
{age = currentDate – dateOfBirth}

Student Course Course


Offering
name * Registers For * * Scheduled For 1 crseCode
ssn registrants term crseTitle
dateOfBirth section creditHrs
/age
*
* /participants

/Takes

with a hollow triangle pointing toward the superclass. In Figure 13-9b (corresponding
to Figure 3-3), for instance, we have combined the generalization paths from Outpatient
to Patient, and from Resident Patient to Patient, into a shared segment with a triangle
pointing toward Patient. We also specify that this generalization is dynamic, meaning
that an object may change subtypes.

FIGURE 13-9 Examples of


generalization, inheritance,
Employee and constraints
(a) Employee superclass with
empName three subclasses
empNumber
address
dateHired

printLabel( )

employee employee employee


type type type
{disjoint, incomplete}

Hourly Salaried
Consultant
Employee Employee
hourlyRate annualSalary contractNumber
stockOption billingRate

computeWages( ) contributePension( ) computeFees( )

(b) Abstract Patient class with


two concrete subclasses
Patient Physician
{abstract}
* Treated By 1 physicianID
patientID
patientName
admitDate

{complete, disjoint}
residency
<<dynamic>>

Outpatient Resident Patient Bed


0..1 Assigned To 1
checkbackDate dateDischarged bedNumber
524 Part V • Advanced Database Topics

Notice that in Figure 13-9b, the Patient class is in italics, implying that it is an
Abstract class abstract class. An abstract class is a class that has no direct instances but whose descen-
A class that has no direct instances dants may have direct instances (Booch, 1994; Rumbaugh et al., 1991). (Note: You can
but whose descendants may have additionally write the word abstract within braces just below or next to the class name.
direct instances. This is especially useful when you generate a class diagram by hand.) A class that can
have direct instances (e.g., Outpatient or Resident Patient) is called a concrete class. In
Concrete class
this example, therefore, Outpatient and Resident Patient can have direct instances, but
A class that can have direct
Patient cannot have any direct instances of its own.
instances.
In Figures 13-9a and 13-9b, the words “complete,” “incomplete,” and “disjoint”
have been placed within braces, next to the generalization. They indicate semantic con-
straints among the subclasses. (In the EER notation, complete corresponds to total special-
ization, and incomplete corresponds to partial specialization.) Any of the following UML
keywords for constraints may be used: overlapping, disjoint, complete, and incomplete,
corresponding to overlapping, disjoint, total, and partial in EER modeling.
In Figure 13-11, we represent both graduate and undergraduate students in a
model developed for student billing. The calcTuition operation computes the tuition a
student has to pay; this sum depends on the tuition per credit hour (tuitionPerCred),
the courses taken, and the number of credit hours (creditHrs) for each of those courses.
The tuition per credit hour, in turn, depends on whether the student is a graduate or
an undergraduate student. In this example, that amount is $900 for all graduate stu-
dents and $750 for all undergraduate students. To denote that, we have underlined the
tuitionPerCred attribute in each of the two subclasses, along with its value. Such an
Class-scope attribute attribute is called a class-scope attribute because it specifies a value common to an
An attribute of a class that specifies entire class rather than a specific value for an instance (Rumbaugh et al., 1991).
a value common to an entire class It is important to note that although the Graduate Student and Undergraduate
rather than a specific value for an Student classes share the same calcTuition operation, they might implement the opera-
instance.
tion in quite different ways. For example, the method that implements the operation
for a graduate student might add a special graduate fee for each course the student
Polymorphism
takes. The fact that an operation with the same name may respond in different ways
The ability of an operation with the
same name to respond in different
depending on the class context is known as polymorphism, a key concept in object-
ways depending on the class oriented systems. The enrollment operation in Figure 13-11 illustrates another example
context. of polymorphism. While the enrollment operation within Course Offering computes

FIGURE 13-11 Polymorphism,


abstract operation, class-scope
attribute, and ordering Student * Registers For * Course * Scheduled For 1 Course
{abstract} Offering {ordered}
crseCode
name term crseTitle
ssn section creditHrs = 3
dateOfBirth
enrollment( ) enrollment( )
address
phone

registerFor(class)
calcTuition( )

Graduate Undergrad
Student Student
undergradMajor satScore
greScore actScore
gmatScore tuitionPerCred = 750
tuitionPerCred = 900

calc-tuition( ) calc-tuition( )
Chapter 13 • Overview: Object-Oriented Data Modeling 525

FIGURE 13-14 Example of


aggregation

Personal
Computer

0..1

1..4 1..* 1 1

CPU Hard Disk Monitor Keyboard ...

the enrollment for a particular course offering or section, an operation with the same
name within Course computes the combined enrollment for all sections of a given course.

Representing Aggregation
An aggregation expresses a Part-of relationship between a component object and an Aggregation
aggregate object. It is a stronger form of association relationship (with the added “part- A part-of relationship between a
of” semantics) and is represented with a hollow diamond at the aggregate end. For component object and an aggregate
example, Figure 13-14 shows a personal computer as an aggregate of CPU (up to four object.
for multiprocessors), hard disks, monitor, keyboard, and other objects (a typical bill-of-
Composition
materials structure). It is also possible for component objects to exist without being part
A part-of relationship in which
of a whole (e.g., there can be a Monitor that is not part of any PC). In composition, a parts belong to only one whole
part object belongs to one and only one whole object; for example, a room is part of only object and live and die with the
one building and cannot exist by itself. whole object.

Summary
In this chapter, we introduced the object-oriented mod- diagrams, using the UML notation, to show you how to
eling approach, which has become popular because it model various types of situations. You also learned how
supports effective representation of a real-world domain— to draw an object diagram that corresponds to a given
in terms of both its data and processes—using a common class diagram. The object diagram provides a snapshot of
underlying representation. We described the activities the actual objects and links present in a system at some
involved in the different phases of the object-oriented point in time.
development life cycle and emphasized the seamless We showed how to model the behaviors and
nature of the transitions that an object-oriented model responsibilities within an application using operations.
undergoes as it evolves through the different phases, from We discussed four types of operations: constructor, query,
analysis to design to implementation. This is in sharp update, and class-scope. The E-R model (as well as the
contrast to other modeling approaches, such as struc- EER model) does not allow you to capture behaviors; it
tured analysis and design, which lack a common underly- allows you only to model the data needs of an organiza-
ing representation and, therefore, suffer from abrupt and tion. In this chapter, we emphasized several similarities
disjoint model transitions. We also discussed the iterative between the E-R model and the object-oriented model,
nature of most object-oriented life cycle models. but, at the same time, highlighted those features that
We presented object-oriented modeling as a high- make the latter more powerful than the former.
level conceptual activity, especially as it pertains to We showed how to represent association relation-
data analysis. We introduced the concept of objects and ships of different degrees—unary, binary, and ternary—
classes and discussed object identity and encapsulation. in a class diagram. An association has two or more roles;
Throughout the chapter, we developed several class each role has a multiplicity, which indicates the number
526 Part V • Advanced Database Topics

of objects that participate in the relationship. Other types means that an operation can apply in different ways
of constraints can be specified on association roles, such across different classes. The concepts of encapsulation,
as forming an ordered set of objects. When an association inheritance, and polymorphism in object-oriented mod-
itself has attributes or operations of its own, or when it eling provide systems developers with powerful mech-
participates in other associations, the association is mod- anisms for developing complex, robust, flexible, and
eled as a class; such a class is called an association class. maintainable business systems.
Links and link objects in an object diagram correspond to The object-oriented model supports aggregation,
associations and association classes, respectively, in a class whereas the E-R or the EER model does not. Aggregation
diagram. Derived attributes, derived relationships, and is a semantically stronger form of association, expressing
derived roles can also be represented in a class diagram. the Part-of relationship between a component object and
The object-oriented model expresses generalization an aggregate object. We distinguished between aggrega-
relationships using superclasses and subclasses, similar tion and generalization and provided you with tips for
to supertypes and subtypes in the EER model. The basis choosing between association and aggregation in rep-
of a generalization path can be denoted using a discrimi- resenting a relationship. We discussed a stronger form
nator label next to the generalization path. Semantic of aggregation, known as composition, in which a part
constraints among subclasses can be specified using object belongs to only one whole object, living and dying
UML keywords such as overlapping, disjoint, complete, together with it.
and incomplete. When a class does not have any direct In this chapter, you also learned how to state
instances, it is modeled as an abstract class. An abstract business rules implicitly, as well as explicitly, in a class
class may have an abstract operation, whose form, but diagram. UML provides several keywords that can be
not method, is provided. used as constraints on classes, attributes, relationships,
In a generalization relationship, a subclass inherits and so on. In addition, user-defined constraints may be
features from its superclass, and by transitivity, from all used to express business rules. When a business rule
its ancestors. Inheritance is a very powerful mechanism involves two or more elements, you saw how to express the
because it supports code reuse in object-oriented systems. rule in a class diagram, such as by using a note symbol. We
We discussed ways of applying inheritance of features, as concluded the chapter by developing a class diagram for
well as reasons for overriding inheritance of operations Pine Valley Furniture Company, illustrating how to apply
in subclasses. We also introduced another key concept in the object-oriented approach to model both the data and
object-oriented modeling, that of polymorphism, which the processes underlying real-world business problems.

Chapter Review
For coverage of key terms, review questions, problems and the chapter, followed by information about additional sources
exercises, and field questions, see the complete chapter on the of information on object data modeling.
textbook’s Web site. The following is the full set of references for

References
Blaha, M., and Rumbaugh, J. 2005. Object-Oriented Modeling and Larman, C. 2004. Applying UML and Patterns: An Introduction to
Design with UML, 2nd ed. Upper Saddle River, NJ: Prentice Object-Oriented Analysis and Design and Iterative Development,
Hall. 3rd ed. Upper Saddle River, NJ: Prentice Hall.
Booch, G. 1994. Object-Oriented Analysis and Design with Rumbaugh, J., M. Blaha, W. Premerlani, F. Eddy, and W.
Applications, 2nd ed. Redwood City, CA: Benjamin/ Lorensen. 1991. Object-Oriented Modeling and Design. Upper
Cummings. Saddle River, NJ: Prentice Hall.
Coad, P., and E. Yourdon. 1991. Object-Oriented Design. Upper Rumbaugh, J., I. Jacobson, and G. Booch. 2004. The Unified
Saddle River, NJ: Prentice Hall. Modeling Language Reference Manual. Reading, MA:
Fowler, M. 2003. UML Distilled: A Brief Guide to the Standard Addison-Wesley.
Object Modeling Language, 3rd ed. Reading, MA: UML Notation Guide. 2003. Needham, MA: Object Management
Addison-Wesley-Longman. Group, available at www.omg.org/cgi-bin/doc?formal
George, J., D. Batra, J. Valacich, and J. Hoffer. 2007. Object- /03-03-10.pdf (accessed November 10, 2011).
Oriented Systems Analysis and Design, 2nd ed. Upper Saddle UML Superstructure Specification. 2009. Needham, MA: Object
River, NJ: Prentice Hall. Management Group, available at http://www.omg.org
Hoffer, J., J. George, and J. Valacich. 2011. Modern Systems Analysis /spec/UML/2.4.1/Superstructure/PDF/ (accessed November 10,
and Design, 6th ed. Upper Saddle River, NJ: Prentice Hall. 2011).
Jacobson, I., M. Christerson, P. Jonsson, and G. Overgaard.
1992. Object-Oriented Software Engineering: A Use Case Driven
Approach. Reading, MA: Addison-Wesley.
Chapter 13 • Overview: Object-Oriented Data Modeling 527

Further Reading
Arlow, J., and I. Neustadt. 2005. UML 2 and the Unified Process: Pilone, D., and N. Pitman. 2005. UML 2.0 in a Nutshell.
Practical Object-Oriented Analysis and Design, 2nd ed. Reading, Sebastopol, CA: O’Reilly.
MA: Addison-Wesley.

Web Resources
www.omg.org Web site of the Object Management Group, a http://www.omg.org/spec/UML/ OMG’s official UML
leading industry association concerned with object-oriented Web site.
analysis and design.

You might also like