© 2007 by prentice hall 1 chapter 14 (web): object-oriented data modeling modern database...

37
© 2007 by Prentice Hall © 2007 by Prentice Hall 1 Chapter 14 (Web): Chapter 14 (Web): Object-Oriented Data Object-Oriented Data Modeling Modeling Modern Database Management Modern Database Management 8 8 th th Edition Edition Jeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden Fred R. McFadden

Post on 20-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

© 2007 by Prentice Hall© 2007 by Prentice Hall 11

Chapter 14 (Web):Chapter 14 (Web): Object-Oriented Data Object-Oriented Data

ModelingModeling

Modern Database Modern Database ManagementManagement

88thth Edition EditionJeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott,

Fred R. McFaddenFred R. McFadden

Page 2: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

22Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

ObjectivesObjectives Definition of termsDefinition of terms Describe phases of object-oriented development Describe phases of object-oriented development

life cyclelife cycle State advantages of object-oriented modelingState advantages of object-oriented modeling Compare object-oriented model with E-R and EER Compare object-oriented model with E-R and EER

modelsmodels Model real-world application using UML class Model real-world application using UML class

diagramdiagram Provide UML snapshot of a system stateProvide UML snapshot of a system state Recognize when to use generalization, Recognize when to use generalization,

aggregation, and compositionaggregation, and composition Specify types of business rules in a class diagramSpecify types of business rules in a class diagram

Page 3: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

33Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

What is Object-Oriented Data What is Object-Oriented Data Modeling?Modeling?

Centers around objects and classesCenters around objects and classes Involves inheritanceInvolves inheritance Encapsulates both data and behaviorEncapsulates both data and behavior Benefits of Object-Oriented ModelingBenefits of Object-Oriented Modeling

Ability to tackle challenging problemsAbility to tackle challenging problems Improved communication between users, analysts, Improved communication between users, analysts,

designers, and programmersdesigners, and programmers Increased consistency in analysis, design, and programmingIncreased consistency in analysis, design, and programming Explicit representation of commonality among system Explicit representation of commonality among system

componentscomponents System robustnessSystem robustness Reusability of analysis, design, and programming resultsReusability of analysis, design, and programming results

Page 4: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

44Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Progressive and interative development process

Page 5: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

55Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

OO vs. EER Data ModelingOO vs. EER Data Modeling

Object OrientedObject Oriented EER

Class Entity typeObject Entity

instanceAssociation RelationshipInheritance of

attributesInheritance of

attributesInheritance of behavior

No representation of behavior

Object-oriented modeling is typically represented using the Unified Modeling Language (UML)Unified Modeling Language (UML)

Page 6: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

66Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Classes and ObjectsClasses and Objects Class: An entity that has a well-defined Class: An entity that has a well-defined

role in the application domain, as well role in the application domain, as well as state, behavior, and identityas state, behavior, and identity Tangible: person, place or thingTangible: person, place or thing Concept or Event: department, Concept or Event: department,

performance, marriage, registrationperformance, marriage, registration Artifact of the Design Process: user Artifact of the Design Process: user

interface, controller, schedulerinterface, controller, scheduler

Object: a particular instance of a classObject: a particular instance of a class

ObjectsObjects exhibit BEHAVIOR as well as attributes Different from entitiesentities

Page 7: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

77Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

State, Behavior, IdentityState, Behavior, Identity

State: attribute types and valuesState: attribute types and values Behavior: how an object acts and Behavior: how an object acts and

reactsreacts Behavior is expressed through Behavior is expressed through

operations that can be performed on itoperations that can be performed on it Identity: every object has a unique Identity: every object has a unique

identity, even if all of its attribute identity, even if all of its attribute values are the samevalues are the same

Page 8: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

88Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Class diagramClass diagram shows the static structure of an object-oriented model: object classes, internal structure, relationships.

Figure 14-2 UML class and object diagram

a) Class diagram showing two classes

Page 9: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

99Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Object diagramObject diagram shows instances that are compatible with a given class diagram.

Figure 14-2 UML class and object diagram (cont.)

b) Object diagram with two instances

Page 10: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1010Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

OperationOperation A function or service that is A function or service that is

provided by all instances of a classprovided by all instances of a class Types of operations:Types of operations:

ConstructorConstructor: creates a new instance of a : creates a new instance of a classclass

QueryQuery: accesses the state of an object but : accesses the state of an object but does not alter its statedoes not alter its state

UpdateUpdate: alters the state of an object: alters the state of an object ScopeScope: operation applying to the class : operation applying to the class

instead of an instanceinstead of an instanceOperations implement the object’s behaviorbehavior

Page 11: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1111Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

AssociationsAssociations AssociationAssociation: :

Named relationship among object classes Named relationship among object classes Association RoleAssociation Role::

Role of an object in an association Role of an object in an association The end of an association where it The end of an association where it

connects to a classconnects to a class MultiplicityMultiplicity: :

How many objects participate in an How many objects participate in an association. Lower-bound..Upper bound association. Lower-bound..Upper bound (cardinality)(cardinality)

Page 12: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1212Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-3Examples of association relationships of different degrees

Lower-bound – upper-bound

Represented as: 0..1, 0..*, 1..1, 1..*

Similar to minimum/maximum cardinality rules in EER

Unary

Binary

Ternary

Page 13: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1313Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Alternative multiplicity representation: specifying the two possible values in a list

instead of a range

Figure 14-4 Examples of binary association relationshipsa) University example

Page 14: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1414Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-4 Examples of binary association relationships (cont.)b) Customer Order example

Page 15: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1515Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-5Object diagram for customer order example

Page 16: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1616Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Association ClassAssociation Class An association that has attributes or An association that has attributes or

operations of its own or that operations of its own or that participates in relationships with participates in relationships with other classesother classes

Like an associative entity in ER Like an associative entity in ER modelmodel

Page 17: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1717Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Binary association class with behavior

Unary association with only attributes and no behavior

Figure 14-6 Association class and link object a) Class diagram showing association classes

Page 18: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1818Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Association class instances

Figure 14-6 Association class and link object (cont.)b) Object diagram showing link objects

Page 19: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

1919Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-7 Ternary relationship with association class

Page 20: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2020Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-8 Derived attribute, association, and role

Derived attributes and relationships shown with / / in front of the name

Derived relationship (from Registers-for and Scheduled-for)

Constraint expression for derived attribute

Derived attribute

Page 21: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2121Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Generalization/Generalization/SpecializationSpecialization

Subclass, superclassSubclass, superclass similar to subtype/supertype in EERsimilar to subtype/supertype in EER

Common attributes, relationships, andCommon attributes, relationships, and operationsoperations

Disjoint vs. OverlappingDisjoint vs. Overlapping Complete (total specialization) vs. Complete (total specialization) vs.

incomplete (partial specialization)incomplete (partial specialization) Abstract Class: no direct instances possible, Abstract Class: no direct instances possible,

but subclasses may have direct instancesbut subclasses may have direct instances Concrete Class: direct instances possibleConcrete Class: direct instances possible

Page 22: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2222Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-9 Examples of generalization, inheritance, and constraints

a) Employee superclass with three subclasses

Shared attributes and operations

An employee can only be one of these subclasses

An employee may be none of them.

Specialized attributes and operations

Page 23: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2323Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-9 Examples of generalization, inheritance, and constraints (cont.)

b) Abstract Patient class with two concrete subclasses

Abstract indicated by italics

A patient MUST be EXACTLY one of the subtypes

Dynamic means a patient can change from one subclass to another over time

Page 24: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2424Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Class-Scope AttributeClass-Scope Attribute

Specifies a value common to an Specifies a value common to an entire class, rather than a specific entire class, rather than a specific value for an instance. value for an instance.

Represented by underliningRepresented by underlining

““=“ is initial, default value=“ is initial, default value

Page 25: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2525Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

PolymorphismPolymorphism

Abstract OperationAbstract Operation: Defines the : Defines the form or protocol of the operation, but form or protocol of the operation, but not its implementationnot its implementation

MethodMethod: The implementation of an : The implementation of an operationoperation

PolymorphismPolymorphism: The same operation : The same operation may apply to two or more different may apply to two or more different classes in different waysclasses in different ways

Page 26: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2626Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-11 Polymorphism, abstract operation, class-scope attribute, and ordering

Class-scope attributes–only one value common to all instances of these classes (includes default values)

This operation is abstract…it has no method at Student level

Methods are defined at subclass level

Page 27: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2727Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Overriding InheritanceOverriding Inheritance

OverridingOverriding: The process of replacing : The process of replacing a method inherited from a superclass a method inherited from a superclass by a more specific implementation of by a more specific implementation of that method in a subclassthat method in a subclass For Extension: add codeFor Extension: add code For Restriction: limit the methodFor Restriction: limit the method For Optimization: improve code by For Optimization: improve code by

exploiting restrictions imposed by the exploiting restrictions imposed by the subclasssubclass

Page 28: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2828Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-12 Overriding inheritance

Restrict job placement

Subclasses that do not override place-student use the default behavior

Page 29: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

2929Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Multiple InheritanceMultiple Inheritance

Multiple ClassificationMultiple Classification: An object : An object is an instance of more than one classis an instance of more than one class

Multiple InheritanceMultiple Inheritance: A class : A class inherits features from more than one inherits features from more than one superclass superclass

Page 30: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3030Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-13 Multiple

inheritance

Page 31: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3131Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

AggregationAggregation AggregationAggregation: A part-of relationship between : A part-of relationship between

a component object and an aggregate objecta component object and an aggregate object

CompositionComposition: A stronger form of aggregation : A stronger form of aggregation in which a part object belongs to only one in which a part object belongs to only one whole object and exists only as part of the whole object and exists only as part of the whole objectwhole object

Recursive AggregationRecursive Aggregation: Composition where : Composition where component object is an instance of the same component object is an instance of the same class as the aggregate objectclass as the aggregate object

Page 32: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3232Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-14 Example of aggregation

A Personal Computer includes CPU, Hard Disk, Monitor, and Keyboard as parts. But, these parts can exist without being installed into a computer. The open diamond indicates aggregation, but not composition

Page 33: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3333Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-15 Aggregation and Composition

(a) Class diagram

(b) Object diagram

Closed diamond indicates composition. The room cannot exist without the building

Page 34: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3434Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-16 Recursive aggregation

Page 35: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3535Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Business RulesBusiness Rules See Chapters 3 and 4See Chapters 3 and 4 Implicit and explicit constraints on objects – Implicit and explicit constraints on objects –

for example:for example: cardinality constraints on association rolescardinality constraints on association roles ordering constraints on association rolesordering constraints on association roles

Business rules involving two graphical Business rules involving two graphical symbols:symbols: labeled dashed arrow from one to the otherlabeled dashed arrow from one to the other

Business rules involving three or more Business rules involving three or more graphical symbols:graphical symbols: note with dashed lines to each symbolnote with dashed lines to each symbol

Page 36: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3636Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-17 Representing business rules

Three-symbol constraint

Two-symbol constraint

Page 37: © 2007 by Prentice Hall 1 Chapter 14 (Web): Object-Oriented Data Modeling Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,

3737Chapter 14-Web © 2007 by Prentice Hall© 2007 by Prentice Hall

Figure 14-18 Class diagram for Pine Valley Furniture Company