You are on page 1of 40

Object Oriented Modeling and

Design with UML


Text Books
1. Object Oriented Modeling and Design with UML
 Michael Blaha and James Rumbaugh

2. Object Oriented Software Architecture, A System of Patterns


 Frank Buschmann, Regine Meunier, …

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 1
NMAMIT, Nitte
Object Oriented Technology
• OO Languages  C++, JAVA etc…
• OO Data Bases  RDBMS has some OO
features.
• OO Modeling  UML (Unified Modeling
Language).
• OO Methodology  Some development
methodologies now routinely incorporate OO
ideas and concepts.
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 2
NMAMIT, Nitte
Object Orientation (OO)  Some Definitions
• Object Orientation (OO)
• Object
• Classification, Class
• Inheritance, Super class, Sub class
• Polymorphism
• Operation, Method

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 3
NMAMIT, Nitte
OO Development
• The way of thinking about software based on
abstractions that exist in the real world as well
as in the program.
• Development refers to the software life cycle:
analysis, design and implementation.
• The essence of OO development is the
identification and organization of application
concepts, rather than their final representation
in the programming language.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 4
NMAMIT, Nitte
Exercise
1.2 OO Development
1.2.1 Modeling Concepts
1.2.2 OO Methodology : Analysis, System design, Class design, Implementation.
1.2.3 Three Models :
Class Model  Class Diagram
State Model  State Diagram
Interaction Model  Starts with use cases.
 Sequence diagram and activity diagram.
1.3 OO Themes
1.3.1 Abstraction
1.3.2 Encapsulation
1.3.3 Combining Data and Behavior
1.3.4 Sharing
1.3.5 Emphasis on the essence of an object
1.3.6 Synergy
1.4 Evidence for usefulness of OO Development
1.5 OO Modeling History

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 5
NMAMIT, Nitte
Modeling as Design Technique
• Model is an abstraction of something for the
purpose of understanding it before building it.
• Steps to build complex systems:
– The developer must abstract different views of the systems,
– Build models using precise notations,
– Verify that the models satisfy the requirements of the
system, and
– Gradually add detail to transform the models into an
implementation.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 6
NMAMIT, Nitte
Purposes of Modeling

• Testing a physical entity before building it.

• Communication with customers.

• Visualization.

• Reduction of complexity.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 7
NMAMIT, Nitte
Abstraction
• Abstraction is the selective examination of certain
aspects of a problem.
• The goal of abstraction is to isolate those aspects that
are important for some purpose and suppress those
aspects that are unimportant.
• All abstractions are incomplete and inadequate.
• Most computer languages are poor vehicles for
modeling algorithms because they force the
specification of implementation details that are
irrelevant to the algorithm.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 8
NMAMIT, Nitte
Three Models
• Class Model: represents the static, structural, “data”
aspects of a system.
• State Model: represents the temporal, behavioral,
“control” aspects of the system.
• Interaction Model: represents the collaboration of
individual objects, the “interaction” aspects of the system.
– A typical software procedure incorporates all three aspects :
• It uses data structures (Class Model),
• It sequences operations in time (State Model)
• It passes the data and control among the objects (Interaction Model)

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 9
NMAMIT, Nitte
Class Modeling
• A Class model captures the static structure of
a system by characterizing the objects in the
system, the relationships between the
objects, and the attributes and operations for
each class of objects.
• Class models provide an intuitive graphic
representation of a system and are valuable
for communicating with customers.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 10
NMAMIT, Nitte
Object and Class
• Objects:
• The purpose of class modeling is to describe objects.
• An object is a concept, abstraction, or thing with identity that has
meaning for an application. The identity means that objects are
distinguished by their inherent existence and not by descriptive
properties that may have.

• Class:
• A class describes a group of objects with the same properties
(attributes), behavior (operations), kinds of relationships, and
semantics.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 11
NMAMIT, Nitte
Class Diagram
• Class diagrams provide a graphic notation for
modeling classes and their relationships,
thereby describing possible objects.
• Class diagrams are useful both for abstract
modeling and for designing actual programs.
• Class diagrams are concise, easy to
understand, and work well in practice.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 12
NMAMIT, Nitte
Object diagram
• It shows individual objects and their
relationships.
• Object diagrams helpful for documenting test
cases and discussing examples.
• A Class diagram corresponds to an infinite set
of object diagrams.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 13
NMAMIT, Nitte
Modeling Notations
• Class Diagram: • Object Diagram:

Person Abc : Person

Pqr : Person

: Person
• UML symbol for class is a box, • UML symbol for object is a box with an
list the class name in boldface, object name followed by a colon
center the name in the box, and followed by the class name. List the class
capitalize the first letter. name and object name in boldface,
center the name in the box, and
capitalize the first letter.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 14
NMAMIT, Nitte
Values and Attributes
• A Value is piece of data.
• An attribute is a named property of a class that describes a value
held by each object of the class.
• Example for attribute: Name, DOB, and weight are attributes for
person objects. Color, modelYear, and weight are attributes of Car
objects.
• Each attribute has a value for each object.
• Attribute should describe values but not objects.
• Unlike objects, values lack identity.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 15
NMAMIT, Nitte
Modeling Notation
• Class Person has attributes Name and DOB. Name as a string and DOB as a date.
– One object in class Person has the value “Joe Smith” for name, and the value
“21 October 1983” for DOB.
– Another object has the value “Mary Sharp” for name and “16 March 1950” as DOB.

Person JoeSmith : Person MarySharpPerson

name : string name = “Joe Smith” name “Mary Sharp”


dob : date dob = 21 October 1983 dob = 16 March 1950

Class with attributes Objects with values


UML Notation lists attributes in the second compartment of the class box. Optional details
such as type and default value, may follow each attribute. A colon precedes the type. An
equal sign precedes the default value. Attribute name values are shown in regular face,
left align the name in the box, and use a lower case letter for the first letter.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 16
NMAMIT, Nitte
Do not list object identifiers; they are
implicit in models
Person Person

personID: ID name : string


name : string dob : date
dob : date homeTelephoneNumber:string
homeTelephoneNumber:string

Wrong Representation Correct Representation

• Do not confuse internal identifiers with real world attributes. Internal identifiers
are purely an implementation convenience and have no application meaning.
• But Tax payer number, license plate number, and telephone number are not
internal identifiers because they have meaning in the real world. They are
legitimate attributes.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 17
NMAMIT, Nitte
Operations and Methods
ClassName

attributeName1 : dataType1 = default value1


AttributeName2 : dataType2 = default value2

operationName1 (argumentList1): resultType1
operationName1 (argumentList1): resultType1

• The attribute and operation compartment are optional; we may or may not show them.
• A missing attribute compartment means that attributes are unspecified.
• Similarly, A missing operation compartment means that operations are unspecified.
• An empty compartment means that the attributes (or operations) are specified and that
there are none.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 18
NMAMIT, Nitte
Link and Association concepts
• A Link is a physical or conceptual connection among objects. Example : JoeSmith WorksFor
Simplex Company.
• An Association is a description of a group of Links with common structure and common semantics.

Person OwnsStock Person


Class Diagram
name : string
* * name

Joe : Person
name = “Joe”

Joe : Person GE:Company


name = “Joe” Name = “GE”

Object Diagram Mary:Person


name “Mary”

Alice:Person
name “Alice” IBM:Company
Sue:Person Name = “IBM”

name “Sue”
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 19
NMAMIT, Nitte
UML Notation for links and association
• UML Notation for link is a line between objects; a line may consist of several line
segments. If the link has a name, it is underlined. Example:
John Owns the stocks in GE Company.
• An association connects related classes and is also denoted by a line (multiple
line segments may be possible).
• Show both link and association names in italics.
• Arrange the classes in an association to read from left–to–right, if possible.
• When there are multiple associations between the same classes, we must use
association names or association end names to resolve the ambiguity.
• Associations are bi directional. But the name of the binary association reads in a
particular direction, but the binary association can be traversed in either
direction. For example: “WorksFor” connects person to company. The inverse of
“WorksFor” could be “Employs”, and it connects a company to a person.
• A “reference” is an attribute in one object that refers to another object.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 20
NMAMIT, Nitte
Multiplicity
• Multiplicity specifies the number of instances of one
class that may relate to a single instance of an
associated class.
• It is a subset of nonnegative integers.
• UML diagrams explicitly list multiplicity at the ends of
association lines.
• UML specifies multiplicity with an interval, such as
“1” (exactly one), “ 1 . . * ” (one or more), or “ 3 . . 5
” ( three to five ). The special symbol * denotes
“many” (zero or more).

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 21
NMAMIT, Nitte
One – to – one association
Country HasCapitalCity CapitalCity
name 1 1 name

Canada:Country HasCapitalCity Ottava:CapitalCity


Name = “Canada” Name = “Ottava”

France:Country HasCapitalCity Paris:CapitalCity


Name = “France” Name = “Paris”
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 22
NMAMIT, Nitte
Zero or one Multiplicity
1 0 . .1
Workstation console
Window

• It is an optional whether an object is involved


in an association.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 23
NMAMIT, Nitte
Association Vs Link
anAssociation aLink
A B A1:A B1:B
* *
anAssociation aLink
A * * B A1:A B1:B
otherLink
*otherAssociation*

Class Diagram Object Diagram

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 24
NMAMIT, Nitte
Association End Names
• A name appears next to the association end.
• Example: Person and Company participate in association
“WorksFor”. A person is an employee, with respect to the
company. A company is an “employer” with respect to a
person.
• Use of association names is optional, but it is easier and less
confusing to assign association end names instead of
association names.

employee employer
Person * 0 .. 1 Company
WorksFor

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 25
NMAMIT, Nitte
Self Association
• Container and content distinguish two usages of
directory in the self association.

Owner 1 * 0..1 container

User Directory

authorisedUser * * * contents

• Association end names are necessary for association between two objects
of the same class. They can also distinguish multiple associations between
a pair of classes.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 26
NMAMIT, Nitte
Ordering
• Objects have an explicit order.
• The ordering is an inherent part of the association.
• We can indicate an ordered set of objects by writing
“{ordered}” next to the appropriate association end.
• Example: A workstation screen containing a number of
overlapping windows. Each window on a screen occurs at
most once. The windows have an explicit order, hence only
the top most window is visible at any point on the screen.
{ordered}
Screen 1
Window
VisibleOn *
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 27
NMAMIT, Nitte
Bags and Sequences
• Multiple links are permitted for a pair of objects by annotating an association
end with {bag} or {sequence} .
• A bag is a collection of elements with duplicates allowed.
• A sequence is an ordered collection of elements with duplicates allowed.
• “Bag” and “sequence” are permitted only for binary associations.
• An itinerary is a sequence of airports and the same airport can be visited
more than once.
{sequence}
Itinerary Airport
* *
• Both {ordered} and {sequence} are same except that the {ordered}
disallows duplicates and the {sequence} allows them.
• A {sequence} association is an ordered bag, while an {ordered}
association is an ordered set.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 28
NMAMIT, Nitte
Association classes
• Association class is an association that is also a class.
• The instances of an association class derive identity from instances of the
constituent classes.
• An association class can have attributes and operations and participate in
associations.
• The UML notation for association class is a box (a class box) attached to
the association by a dashed line.
• Example: accessPermission is an attribute of AccessibleBy. The sample
data at the bottom of the figure shows the value for each link.
File * * User
Accessible
accessPermission
“accessPermission” is a joint property of File and User and cannot be
attached to either File or User alone without losing information.
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 29
NMAMIT, Nitte
Consider this example
• Each person working for a company receives a salary and has a
job title. The boss evaluates the performance of each worker.
The attributes may also occur one–to–one associations.

Person 0..1 Company


*
name
boss birthDate Name
0..1 address WorksFor address
salary
Manages * jobTitle

PerformanceRating

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 30
NMAMIT, Nitte
Which one is preferred and why?
Person 0..1 Company
*
name
Name
birthDate
address
address WorksFor
salary
jobTitle

Person WorksFor 0..1 Company


*
name
Name
birthDate
address
address
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 31
NMAMIT, Nitte
Proper use of association classes
• Do not fold attributes of an association into a class
because multiplicity of association might change.
Person 0..1 Company
*
Preferred name
Name
Form birthDate
address
address WorksFor
salary
jobTitle

Person WorksFor 0..1 Company


Not *
Preferred name
Name
Form birthDate
address
address
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 32
NMAMIT, Nitte
Association class participating in an association
• Users may be authorized on many workstations. Each authorization
carries a property and access privileges. A User has a home directory
for each authorized workstation, but several workstations and users
can share the same home directory. Association classes are important aspect
of class modeling because they specify identity and navigation paths precisely.

User * * Workstation

Authorization
priority homeDirecory
privileges 1
Directory
*
startSession

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 33
NMAMIT, Nitte
Association class vs. Ordinary class
• The association class has only one occurrence for each pairing of Person and
Company. But there can be any number of occurrences of a Purchase for
each Person and Company. Each Purchase is distinct and has its own
quantity, date, and cost.

Person 0..1 Company


*
Association name name
class OwnsStock
quantity

Person 1 Purchase 1 Company


* quantity *
Ordinary name name
class date
cost

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 34
NMAMIT, Nitte
Qualified Associations
• A qualified association is an association in which an attribute called the
qualifier disambiguates the objects for a “many” association end. It is possible to
define qualifiers for “one to many” and “many to many” associations.
• Qualifier selects among the target objects, reducing effective multiplicity, from
“many” to “one”.
• Qualified associations with a target multiplicity of “one” or “zero–or–one” specify a
precise path for finding the target object from the source object.
• Example: Bank services multiple accounts. An account belongs to a single bank.
Within a bank, the account number specifies a unique account. Bank and Account
are classes. And accountNumber is a qualifier. This qualification reduces the
effective multiplicity of this association from “one–to–many” to “one–to–one”.
1 0 ..1
accountNumber

1 *

accountNumber
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 35
NMAMIT, Nitte
Generalization and Inheritance
• Definition of Generalization: Generalization is the
relationship between a class (the super class) and one or
more variations of class (the sub classes).
• Generalization organizes classes by their similarities and
differences, structuring the description of objects. The
super class holds common attributes, operations and
associations. Each sub class is said to inherit the features
of its super class.
• Generalization is called the “is–a” relationship, because
each instance of a sub class is an instance of super class.
• Simple Generalization organizes classes into a hierarchy;
(single sub class has a single immediate super class).
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 36
NMAMIT, Nitte
UML notation for Generalization
• A large hollow arrow head points to the super
class. Super class is on top, and sub classes on
bottom. Curly bracket denotes UML Comment.
• Instance of a subclass is simultaneously an
instance of all its ancestor classes.
• Example: Refer figure in Page#38 and # 39.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 37
NMAMIT, Nitte
Uses of Generalization
• Support for polymorphism.
• To structure the description of objects.
• To enable re use of code.

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 38
NMAMIT, Nitte
Object Constraint Language (OCL)
• Refer Books

Venkatesh Bhat, Dept. of CSE,


Tuesday, December 7, 2021 39
NMAMIT, Nitte
End of
Chapter – 1
Venkatesh Bhat, Dept. of CSE,
Tuesday, December 7, 2021 40
NMAMIT, Nitte

You might also like