OO Concepts and Modeling With UML
OO Concepts and Modeling With UML
Outline of topics
Basic Concepts of Object Orientation
Abstraction
Hierarchy
Encapsulation
Modularity
Polymorphism
Class, Object, attribute methods(services)….
Component, Interface…etc.
Patterns
OO Method Wars and the Unification Process
UML- Unified Modeling Language
Definition
UML Structure( Building Blocks)
UML- Architectural Views
UML –Diagram types ( Structure, Behavior and Interaction)
UML Diagram Examples
A Modern Look at Modelling
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
3
method
#6
method method
#5 #4
Inheritance
The mechanism where features in a hierarchy inherit from superclasses to subclasses
“is a”
Aggregation
The process of creating a new object from two or more other objects.
“part of ”
A car is an aggregation of engine, wheel, body...
Example
Inheritance
Simply stated, inheritance is a relationship among classes wherein one class shares the structure
and/or behavior defined in one (single inheritance) or more (multiple inheritance) other classes
The implicit possession by all subclasses of features defined in its super classes
subclasses of the
furniture superclass
instances of chair
Single Inheritance
Classes
Attributes
Objects
Polymorphism
Message and Methods
Real-world objects are not the only kinds of objects that are of interest to us
during software development.
inventions of the design process whose collaborations with other such objects serve as the
mechanisms that provide some higher-level behavior.
Jacobson et al. define control objects (Controller objects) as “the ones that unite courses of events and
thus will carry on communication with other objects”.
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
22
Classes
Objects
Class????
Classes
A class:
A unit of abstraction in an object oriented (OO) program
Starts with definition of concepts such as
template
generalized description
pattern
“blueprint” ... describing a collection of similar items.
In the context of object-oriented analysis and design, Class is define as follows:
A class is a set of objects that share a common structure, common behavior, and common
semantics.
A class represents a set of objects( instances) that share a common structure and a common
behavior
A kind of software module
Describes its instances’ structure (properties)
Contains methods to implement their behavior
Like a class, an interface can have methods and variables, but the
methods declared in interface are by default abstract (only method
signature, they have no “body”).
Interfaces specify what a class must do and not how it does. It is the
blueprint of the class.
A class serves as a sort of a binding contract between an abstraction and all of
its clients.
These contract decisions are captured in the interface of a class and a strongly typed programming
language can detect violations of this contract during compilation of the class.
Classes implement one or more interfaces
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
30
interface Vehicle { {
int speed;
int gear;
// to increase speed
void speedUp(int a); @Override
public void speedUp(int increment){
speed = speed + increment;
void applyBrakes(int a); }
// to decrease speed
@Override
} public void applyBrakes(int decrement){
speed = speed - decrement;
}
public void printStates() {
System.out.println("speed: " + speed
+ " gear: " + gear);
}
}
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling 31
32
Messages
sender object
attributes:
receiver object
attributes:
operations:
operations:
message:
[sender, return value(s)]
Polymorphism
The mechanism by which several methods can have the same name and implement
the same abstract operation.
For example as in Interfaces?
Persistence
Abstract and Concrete Classes
Abstract Classes cannot be instantiated while concrete class can be
Persistence focuses on the issue of how to make objects available
for future use.
To make an object persistent, you must save the values of its attributes to
permanent storage (such as a relational database or a file) as well as any
information needed to maintain the relationships (aggregation,
inheritance, and association) with which it is involved.
In addition to saving objects, persistence is also concerned with their
retrieval and deletion.
Business/domain classes are usually persistent.
Need to store both attributes and associations
User-interface classes are usually transitory
Interfaces ( Recap)
Components
Pattern
Unification
The Unification
Based on the fact that differences between the various
methods were becoming smaller.
The method wars did not move OOT any longer.
Jim Rumbaugh and Grady Booch decided at the end of
1994 to unify their work within a single method: the
Unified Method.
Definition of a universal language for O-O modeling
Unified Method 0.8 Oct. 1995
THE UNIFICATION…
A year later they were joined by Ivar Jacobson
Objective: Standardization of the o-o development process
The Unified Method was transformed into UML- the Unified Modeling Language
June 1996 UML 0.9
Sept 1996 UML 0.91
OOPSLA (Object-Oriented Programming, Systems, Languages & Applications) an annual ACM
research conference was created in 1996.
04/09/2023
Chapter 2 Basic OO Concepts and UML Modeling
48
Booch ‘91
OMT - 1
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
49
UML Cont’d…
Aims at
Unifying design languages
Being a general purpose modeling language
What UML IS
UML- Purposes
Visualizing
explicit model facilitates communication
some structures transcend (pass or more) what can be represented in programming language
each symbol has well-defined semantics behind it.
Specifying
The UML addresses the specification of all important analysis, design, and implementation decisions.
Constructing
Forward engineering: generation of code from model into programming language
Reverse engineering: reconstructing model from implementation
Round-trip engineering: going both ways.
Documenting
Produce consistent models of a system for reference and communication.
UML as blueprint
relatively detailed design diagrams used either for reverse engineering to visualize and
better understand existing code,
or for forward engineering to guide for code generation, either manually or automatically
with a tool.
Common Architecture
Building blocks mechanisms
(Patterns)
Architectural Views
Building blocks Common mechanisms use-case view
things specifications logical view
relationships
Diagrams
Adornments/decoration process view
common divisions implementation view
extensibility mechanisms deployment view
RULES OF UML
UML’s building blocks should be put together to develop a well-formed model.-A model
that is semantically self-consistent and is in harmony with all its related models.
Things
Structural — nouns/static parts of UML models (irrespective of time).
Nouns.
Conceptual or physical elements.
setGrade()
getGrade()
State Machine
specifies the sequence of states an object
or
an interaction goes through during its
lifetime in response to events.
University Administration
-Student
+Department
operation()
flexible {for all g in children
drop-out dates }
g.operation()
Student
3. Realization IGrade
One element guarantees to carry out what is expected by the other element.
(e.g, interfaces and classes/components; use cases and collaborations)
4. Extensibility mechanisms
UML can be extended using the following mechanisms
Stereotypes: Extends the vocabulary of UML, allowing you to create new kinds of building blocks that are
derived from existing ones but that are specific to your problem.
Stereotypes (<< >>) can be used to extend the UML notational elements
Stereotypes may be used to classify and extend associations, inheritance relationships, classes, and components
Examples:
Class stereotypes: boundary, control, entity, utility, exception
Inheritance stereotypes: uses and extends
Component stereotypes: subsystem
Constraints: Extends the semantics of a UML building block, allowing you to add new rules or modify
existing ones.
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
70
Architectural View
Architecture is a set of significant decisions about
The organization of a software system
The selection of the structural elements and their interfaces
by which the system is composed
Their behavior, as specified in the collaborations among those
elements
The composition of these structural and behavioral elements
into progressively larger subsystems
The architectural style(pattern) that guide this organization of
components: the static and dynamic elements and their
interfaces, their collaborations, and their composition.
Architectural View
Software architecture is not only concerned with architecture and
behavior, but also with usage, functionality, performance, resilience
(elasticity), reuse, comprehensibility, economic and technology
constraints and trade-offs, and aesthetic concerns.
Architecture of a system can be described by a view from a particular
viewpoint.
A view is simply a subset of UML modeling constructs that represent
one aspect of the system
UML is used for visualizing, specifying, constructing, and documenting
with emphasis on system architectures (things in the system and
relationships among the things) from five different views ( 4+1 view)
Each of the views involve Structural and behavioural models.
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
Architectural Views (Representing Architecture: The 4+1 View Model 72
UML –Viewpoints
Logical/Design views
Supports the functional requirements of the system
Focuses on the things (classes, interfaces and collaborations) that
form the vocabulary of the problem that the system is trying to solve
and the elements of the solution to that problem.
The view encompasses the static and dynamic aspects of the system
End-product: class and object diagram (static),
sequence/collaboration, activity and statechart diagram (dynamic)
Process view
Focuses on the aspects of the system that involves timing and the
flow of program control.
Addresses the performance, scalability and throughput of the system
End product: Activity diagrams
Design View
Encompasses classes, interfaces, and collaborations that define the vocabulary of a system.
Supports functional requirements of the system.
Static aspects in class and object diagrams; Dynamic aspects in interaction (Collaboration/Communication diagram) diagrams.
Process View
Encompasses the threads and processes defining concurrency and synchronization.
Addresses performance, scalability, and throughput.
Static and dynamic aspects captured as in design view; emphasis on active classes.
Implementation View
Encompasses components and files used to assemble and release a physical system.
Addresses configuration management.
Static aspects in component diagrams.
Deployment View
Encompasses the nodes that form the system hardware topology.
Addresses distribution, delivery, and installation.
Static aspects in deployment diagrams;
Chapter 2 Basic OO Concepts and UML
04/09/2023
Modeling
78
system
Use-Case Diagrams
A use-case diagram is a set of use cases
A use case is a model of the interaction between
External users of a software product (actors) and
The software product itself
More precisely, an actor is a user playing a specific role
Use case describes a set of user scenarios
Used in capturing user requirements
Also acts as contract between end user and software developers
Borrow Employee
Client
Order Title
Fine Remittance
Supervisor
Use case: A set of scenarios that describing an interaction between a user and a
system, including alternatives.
System boundary: rectangle diagram representing the boundary between the actors
and the system.
Registrar
Students select 3 core courses and 2 electives
Student
Once a student registers for a semester, the billing system is
notified so the student may be billed for the semester
Billing System
Students may use the system to add/drop courses
for a period of time after registration
Use-Case Diagrams
Association:
Communication between an actor and a use case; Represented by
a solid line.
Use-Case Diagrams
Include: A dotted line labeled <<include>> beginning at base use case and ending with an arrows
pointing to the included use case. The include relationship occurs when a chunk of behavior
is similar across more than one use case. Use “include” in stead of copying the description of
that behavior in multiple places.
<<include>>
Extend: A dotted line labeled <<extend>> with an arrow toward the base case. The
extending use case may add behavior to the base use case. The base use case
declares “extension points”.
<<extend>>
Use-Case Diagrams
Use-Case Diagrams
Both Make Appointment and
Request Medication include
Check Patient Record as a
subtask (include)
Class Diagram
A class diagram depicts classes and their
interrelationships
Used for describing structure and behavior in the
use cases
Provide a conceptual model of the system in terms
of entities and their relationships
Used for requirement capture, end-user interaction
Detailed class diagrams are used for developers
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
94
Class diagram
Each class is represented by a rectangle subdivided into
three compartments
Name
Attributes
Operations
Modifiers are used to indicate visibility of attributes and
operations.
‘+’ is used to denote Public visibility (everyone)
‘#’ is used to denote Protected visibility (friends and derived)
‘-’ is used to denote Private visibility (no one)
By default, attributes are hidden and operations are visible.
OO Relationships
There are two kinds of Relationships
Generalization (parent-child relationship)
Association (student enrolls in course) – weak relationship.
Associations can be further classified as
Aggregation
An aggregation expresses a part-of relationship between a component object and an
aggregate object. It is a stronger form of an association relationship (with the added
“part-of” semantics) and is represented with a hollow diamond at the aggregate end
( analysis decision)
Composition
A whole/part relationship where one object is composed of one or more other objects,
each of which is considered a part of the whole. This relationship is a strong form of
aggregation in that the lifetimes of the whole and its parts are dependent(physical
design issue).
The choice of aggregation is usually an analysis or architectural design decision; the
choice of composition (physical containment) is usually a detailed, tactical issue.
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
OO Relationships: Generalization
97
Example:
Supertype Customer
Regular Loyalty
Customer Customer
Subtype1 Subtype2
-Inheritance is a required feature of object orientation
-Generalization expresses a parent/child relationship among related classes.
-Used for abstracting details in several layers
OO Relationships: Association
Represent relationship between instances of
classes
Student enrolls in a course
Courses have students
Courses have exams
Etc.
student
1 *
University Person
0..1 *
employer teacher
Multiplicity
Symbol Meaning Role
1 One and only one Role
0..1 Zero or one
“A given university groups many
M..N From M to N (natural language) people; some act as students, others
* From zero to any positive integer as teachers. A given student belongs
0..* From zero to any positive integer to a single university; a given teacher
1..* From one to any positive integer may or may not be working for the
university at a particular time.”
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
100
ScheduleAlgorithm 1
RegistrationForm
0..*
1 RegistrationManager 0..*
addStudent(student, course)
1 Course
name
0..* numberCredits
User
name Student
open()
addStudent(StudentInfo)
major
1
1..10
Professor 1..*
4 CourseOffering
tenureStatus
1 location
0..4
open()
addStudent(StudentInfo)
arch06F: Course
tom: Student
name = “Sw Architecture”
harry1: Professor
name = “Tom Cruise”
name = “Harry William”
alg06F: Course
surie: Professor arch: CourseOffering name = “Adv Algorithms”
name = “Surie Holmes” location = “UTD”
OO Relationships: Aggregation
Container Class
Aggregation:
Class C expresses a relationship among instances of
related classes. It is a specific kind of Container-
AGGREGATION
Containee relationship.
Apples Milk
Whole Class
Class W Association
is a link between classes that indicates that there is
a relationship between these classes.
Model denotes some semantic dependency among
Class P1 Class P2 otherwise unrelated classes. Very weak
relationship.
Composition
Part Classes Models the “part–whole” relationship but, in addition,
Every part may belong to only one whole, and If the
Example whole is deleted, so are the parts ( physical
containment)- existence dependency.
Example:
A number of different chess boards: Each square belongs to
only one board. If a chess board is thrown away, all 64
squares on that board go as well.
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
106
Easy to describe how classes work by moving cards around; allows to quickly consider
alternatives.
Interaction Diagrams
Show how objects interact with one another
UML supports two types of interaction diagrams
Sequence diagrams
Collaboration diagrams
A lifeline
action name
A call action from an object
to itself
110
return value
111
: Customer : CustomerReview
assignRating()
computeAvgRating()
average rating
112
<<create>> <<create>>
: Class
Sequence Diagram
Destroy action
A destroy action destroys an object
It tells an object to destroy itself
An object can perform a destroy action on another object, or on itself
In the UML, a destroy action is represented as an arrow with the
stereotype <<destroy>> from the object that invokes the action to the
destroyed object. A large X is also added at the end of the destroy
arrow to denote that the object’s lifeline has been terminated
Object: Class : Class
<<destroy>>
X
114
action name
115
Picks up
Dial tone
Dial
Picks up
Hello
[condition] remove()
Condition
*[for each] remove()
Iteration
Self-Call
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
117
Creation
Create message A
Object life starts at that point
Activation Create
B
Symbolized by rectangular stripes
Place on the lifeline where object is
activated.
Rectangle also denotes when object
is deactivated( the end of the
rectangle).
Activation bar
X
Deletion Return
Deletion
Placing an ‘X’ on lifeline
Object’s life ends at that point Lifeline
Message
1: look up ()
•Sequence diagrams demonstrate the
behavior of objects in a use case by 2: title data ()
describing the objects and the messages 3: [not available] res erve title ()
they pass.
4 : title returned ()
6 : borrow title ()
start
6: remove reservation
5: title available
6 : borrow title
1: look up
2: title data
4 : title returned
Catalog
5 : hold title
Collaboration diagrams are equivalent to sequence diagrams. All the features of sequence
diagrams are equally applicable to collaboration diagrams
Interaction diagrams describe how use cases are realized in terms of interacting objects.
Use a sequence diagram when the transfer of information(messages) is the focus of attention
Use a collaboration diagram when concentrating on the objects involved
Displays object interactions organized around objects and their direct links to one another.
Emphasizes the structural organization of objects that send and receive messages.
2: request processing
: Registrar 3: add course
3: add course
4: <<create>> aCourse:
Course
theManager :
aCourse: CurriculumManager
Course 4: <<create>>
Traceability!
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
State Diagrams (Billing Example)
122
State Diagrams show the sequences of states an object goes through during its life cycle in
response to stimuli, together with its responses and actions; an abstraction of all possible
behaviors. A state machine diagram expresses behavior as a progression through a series of
states, triggered by events, and the related actions that may occur.
Initial state happens when object is created, Final state happens when an object ceases to exist.
The transition diagrams of permanent entity types do not have final states, because, by
definition, instances of these types never cease to exist.
State Diagram is also known as
• State Transition Diagram
• (Statechart) Diagram)
Start End
Unpaid Paid
Invoice created payin Invoice destroying
g
State Diagrams (Traffic light example using timer event type)- no final state
initial (internal)
condition
event/action Add student [count < 10]
Add Student /
Initialization Set count = 0
Open
do: Initialize course
entry: Register student
exit: Increment count
Cancel
Cancel [ count = 10 ]
Canceled
do: Notify registered students
Closed
Cancel do: Finalize course
final
• A special kind of statechart diagram that shows the flow from activity to activity.
initial
fork/spawn
Synchronization(join)
[else]
[ count < 10 ]
guard
Close course final
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
131
User
Course People.dll
Course.dll
Student Professor
Course Course
Offering
Student Professor
wireless
Library Server Main Building Solaris
People.dll Billing.exe
Dorm PC
People Database
Student
Professor
Rational Rose(IBM)
MS-Visio –(Microsoft)
Conceptdraw
Lucidchart
ArgoUML
Eclipse UML2 Tools
UCEd
…….
04/09/2023 Chapter 2 Basic OO Concepts and UML Modeling
4. A Modern Look at Modelling. 134
End of Chapter 2