You are on page 1of 34

Object-Oriented Analysis and Design:

Object Modeling – Class Diagrams


Representing Objects and
Classes
 Object: an entity with a well-defined role in
an application domain, and has state,
behavior, and identity characteristics
 State: encompasses an object’s properties
(attributes and relationships) and the
values of those properties

3
Representing Objects and
Classes (Cont.)
 Behavior: represents how an object acts
and reacts
 Identity: uniqueness, no two objects are
the same
 Object class (class): a logical grouping of
objects that have the same (or similar)
attributes, relationships, and behaviors
(methods)
4
Representing Objects and
Classes (Cont.)
 Class diagram: a diagram that shows the
static structure of object classes, their
internal structure, and the relationships in
which they participate
 UML classes are analogous to E-R
entities.

5
Representing Objects and
Classes (Cont.)
Figure 8-26 UML class diagram showing two classes

6
Representing Objects and
Classes (Cont.)
 Operation: a function or a service that is
provided by all the instances of a class to
invoke behavior in an object by passing a
message
 Encapsulation: the technique of hiding
the internal implementation details of an
object from its external view

7
Types of Operations
 Constructor: an operation that creates a
new instance of a class
 Query: an operation that accesses the
state of an object but does not alter the
state
 Update: an operation that alters the state
of an object
 Scope: an operation that applies to a class
rather than an object instance
8
Representing Associations
 Association: a relationship among instances
of object classes
 Association role: the name given to the end
of an association where it connects to a class

9
Representing Associations
 Multiplicity: indicates how many objects
participate in a given relationship:
 0..10means minimum of 0 and maximum of 10
 1, 2 means can be either 1 or 2
* means any number
 UML associations are analogous to E-R
relationships and UML multiplicities are analogous
to E-R cardinalities.

10
Representing Associations (Cont.)

Figure 8-27
Examples of
association
relationships of
different degrees

11
Representing Associations (Cont.)
Figure 8-28 Examples of binary associations

12
Representing Associative
Classes
 Associative class: an association that has
attributes or operations of its own or that
participates in relationships with other classes
 UML association classes are analogous to E-R
associative entities.
 Generalization and inheritance implemented via
superclass/subclasses in UML,
supertypes/subtypes in E-R.

13
Representing Associative
Classes (Cont.)
Figure 8-29 Class diagram showing associative classes

14
Representing Stereotypes for
Attributes

Figure 8-31 Stereotypes

15
Representing Generalization
 Abstract class: a class that has no direct
instances but whose descendants may have
direct instances
 Concrete class: a class that can have direct
instances

16
Representing Generalization
(Cont.)
Figure 8-32 Example of generalizations, inheritance, and constraints

17
Representing Generalization
(Cont.)
 UML keywords:
 Overlapping: a descendant may be
descended from more than one of the
subclasses
 Disjoint: a descendant may not be descended
from more than one of the subclasses

18
Representing Generalization
(Cont.)
 Complete: all subclasses have been specified
 Incomplete: some subclasses have been
specified, but the list is known to be
incomplete
 Class-scope attribute: an attribute of a
class that specifies a value common to an
entity class, rather than a specific value for
an instance

19
Representing Generalization
(Cont.)
Figure 8-33 Polymorphism, abstract operation, class-scope attribute, and ordering

20
Representing Generalization
(Cont.)
 Abstract operation: defines the form or
protocol of the operation, but not its
implementation
 Method: the implementation of an operation
 Polymorphism: the same operation may apply
to two or more classes in different ways

21
Representing Aggregation
 Aggregation: a part-of relationship
between a component object and an
aggregate object
 Represented with open diamonds
 Composition: a part object that belongs
to only one whole object and that lives and
dies with the whole
 Represented with filled diamonds

22
Aggregation and Composition
(Cont.)
Figure 8-34 Aggregation and composition

23
Composition
 If a class ‘Car’ has a composition relationship with
another class ‘Wheel’, we should agree that
normally the multiplicity of Wheel is 4 (exactly)
 ‘Vehicle’, on the other hand, could have any number
of wheels (0..*)
 Composition is a special form of association
 It is important enough to have its own notation
Composition

Airplane

2 1 1 1
Wing Propeller Fuselage Tail
Aggregation
 Aggregations is also a type of association,
but again, a special one that is given its
own notation
 This
is because, like composition, it is very
common
 An aggregation is another relationship
between classes which says one class ‘is
a part of’ another class
Aggregation vs. Composition
 Both aggregation and composition
represent the ‘is a part of’ relationship
 The main difference is what the part
represents
 In aggregation, the part (constituent) is
meaningful without the whole (aggregate)
 In composition, the part (component) is not
meaningful without the whole (container)
Aggregation vs. Composition
 A side-effect of this difference is that a
component is always a part of (at most)
one container
 However, a constituent may be a member of
multiple aggregates
Aggregation vs. Composition
 In UML, composition is considered a
special case of aggregation where
constituents belong only to a single
aggregate
 This is why some tools (such as Rational
Rose) only have symbols for aggregation, and
not composition
Aggregation
 To illustrate an constituent, again, let’s use
a few examples:
 A Forest is an aggregate of Trees
 A Program is an aggregate of Statements
 A Fleet is an aggregate of Ships
 A Deck is an aggregate of Cards
Aggregation
 Parts of an aggregate are called
constituents:
 A Tree is an constituent of Forest
 A Statement is an constituent of Program
 A Ship is an constituent of Fleet
 A Card is an constituent of Deck
Aggregation
 These constituents share one common property:
 The constituents of an aggregate are usually the same
type
 Two other properties are also defined for
aggregation:
 An object may be a constituent of more than one
aggregate simultaneously
 It is possible to have an aggregate without any
constituents
Aggregation
 An object may be a constituent of more
than one aggregate simultaneously
 Thisis identified by the multiplicity of the
aggregate end of the association
 It is possible to have an aggregate without
any constituents
 Thisis identified by the multiplicity of the
constituent end of the association
An Example of Conceptual Data
Modeling at Hoosier Burger

Figure 8-35 Level-0 data flow diagram for Hoosier Burger’s new
logical inventory control system
34
An Example of Conceptual Data
Modeling at Hoosier Burger (Cont.)

Figure 8-36 Reduced decision table for Hoosier Burger’s inventory reordering
35

You might also like