1 Chapter 14: Chapter 14: Object-Oriented Data Object-Oriented Data Modeling Modeling
Dec 24, 2015
22Chapter 14
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, Improved communication between users,
analysts, designer, and programmersanalysts, designer, and programmers• Increased consistency in analysis and designIncreased consistency in analysis and design• Explicit representation of commonality among Explicit representation of commonality among
system componentssystem components• System robustnessSystem robustness• Reusability of analysis, design, and programming Reusability of analysis, design, and programming
resultsresults
33Chapter 14
OO vs. EER Data ModelingOO vs. EER Data Modeling
Object OrientedObject Oriented EER
Class Entity typeObject Entity instanceAssociation RelationshipInheritance of attributes Inheritance of attributesInheritance of behavior No representation of
behavior
Object-oriented modeling is frequently accomplished using the Unified Modeling Language (UML)Unified Modeling Language (UML)
44Chapter 14
ObjectObject An entity that has a well-defined role in An entity that has a well-defined role in
the application domain, as well as state, the application domain, as well as state, behavior, and identitybehavior, 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
ObjectsObjects exhibit BEHAVIOR as well as attributes Different from entitiesentities
55Chapter 14
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
66Chapter 14
Figure 14-2 –UML class and object diagrams
(a) Class diagram showing two classes
Class diagramClass diagram shows the static structure of an object-oriented model: object classes, internal structure, relationships.
77Chapter 14
(b) Object diagram with two instances
Object diagramObject diagram shows instances that are compatible with a given class diagram.
88Chapter 14
OperationsOperations 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 operators:Types of operators:
• 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 instance
Operations implement the object’s behaviorbehavior
99Chapter 14
AssociationsAssociations AssociationAssociation: :
• Relationship among object classes 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 connects The end of an association where it connects
to a classto 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).
1010Chapter 14
Figure 14-3 –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
1111Chapter 14
Figure 14-4 – Examples of binary association relationships (a) University example
Alternative multiplicity representation: specifying the two possible values in a list
instead of a range
1212Chapter 14
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
1313Chapter 14
Figure 14-6 – Association class and link object
(a) Class diagram showing association classes
Binary association class with behavior
Unary association with only attributes and no behavior
1515Chapter 14
Generalization/Generalization/SpecializationSpecialization
Subclass, superclassSubclass, superclass• similar to subtype/supertype in EERsimilar to subtype/supertype in EER
Common attributes, relationships, Common attributes, relationships, AND 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 instancesAbstract Class: no direct instances Concrete Class: direct instancesConcrete Class: direct instances
1616Chapter 14
PolymorphismPolymorphism Abstract Operation: Defines the form Abstract Operation: Defines the form
or protocol of the operation, but not or protocol of the operation, but not its implementation. its implementation.
Method: The implementation of an Method: The implementation of an operation.operation.
PolymorphismPolymorphism: The same operation: The same operation may apply to two or more classes in may apply to two or more classes in
different waysdifferent ways
1717Chapter 14
Figure 14-11 – Polymorphism, abstract operation, class-scope attribute, and ordering
Class-scope attributes – only one value common to all instances of these classes
This operation is abstract…it has no method at Student level
Methods are defined at subclass level
1818Chapter 14
Overriding InheritanceOverriding Inheritance Overriding: The process of replacing Overriding: 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 subclass.that method in a subclass.• For Extension: add code.For Extension: add code.• For Restriction: limit the method. For Restriction: limit the method. • For Optimization: improve code by For Optimization: improve code by
exploiting restrictions imposed by the exploiting restrictions imposed by the subclass.subclass.
2020Chapter 14
Multiple InheritanceMultiple Inheritance Multiple Classification: An object is Multiple Classification: An object is
an instance of more than one class.an instance of more than one class.
Multiple Inheritance: A class inherits Multiple Inheritance: A class inherits features from more than one features from more than one superclass. superclass.
2222Chapter 14
AggregationAggregation Aggregation: A part-of relationship Aggregation: A part-of relationship
between a component object and an between a component object and an aggregate object.aggregate object.
Composition: A stronger form of Composition: A stronger form of aggregation in which a part object aggregation in which a part object belongs to only one whole object and belongs to only one whole object and exists only as part of the whole object. exists only as part of the whole object.
Recursive Aggregation: composition Recursive Aggregation: composition where component object is an where component object is an instance of the same class as the instance of the same class as the aggregate object.aggregate object.
2525Chapter 14
Object Query Language (OQL)Object Query Language (OQL) OQL is an object-based version of SQL designed specifically OQL is an object-based version of SQL designed specifically
for Object Oriented Frameworks.The differences between for Object Oriented Frameworks.The differences between OQL and traditional SQL are:OQL and traditional SQL are:
OQL has the ability to support object referencing within OQL has the ability to support object referencing within
tables. It is possible to have objects nested within objects.tables. It is possible to have objects nested within objects.
Not all SQL keywords are supported within OQL; irrelevant Not all SQL keywords are supported within OQL; irrelevant keywords have been removed from the syntax.keywords have been removed from the syntax.
OQL has the ability to perform mathematical computations OQL has the ability to perform mathematical computations from within OQL statements.from within OQL statements.
2626Chapter 14
OQL (cont.)OQL (cont.) OQL objects - OQL objects - Objects in OQL are Objects in OQL are
created and defined using the created and defined using the CREATE keyword, examples of CREATE keyword, examples of objects in OQL are database(s), objects in OQL are database(s), tables contained within the tables contained within the database(s) and elements such as database(s) and elements such as objects, lists, groups, references to objects, lists, groups, references to objects and atoms contained within objects and atoms contained within the database tables.the database tables.
2727Chapter 14
OQL (cont.) OQL (cont.) Follow a similar Select, From, Where Follow a similar Select, From, Where
format like SQL with a lot of the format like SQL with a lot of the same features, i.e. subqueries, same features, i.e. subqueries, boolean operators, sorting options, boolean operators, sorting options, etc.etc.
Insert, update, deletion functions are Insert, update, deletion functions are similar to SQLsimilar to SQL
Supports joins in a similar fashion to Supports joins in a similar fashion to SQLSQL