Unit 1 Ooad
Unit 1 Ooad
Presented by
Prianka .R.R
What is UML?
• Standard language for specifying, visualizing,
constructing, and documenting the artifacts of
software systems, business modeling and other non-
software systems.
• The UML is a very important part of developing
object oriented software and the software
development process.
• The UML uses mostly graphical notations to express
the design of software projects.
As a Sketch
• Most common use of UML
• Used to help communicate some aspect of a system and to better
understand it
• Used for both forward engineering (i.e., build diagrams before coding) and
reverse engineering (i.e., build diagrams from existing code)
• Strives to be informal and dynamic
• Only emphasizes those classes, attributes, operations, and relationships
that are of interest
• More concerned with selective communication than complete
specification
3
As a Blueprint
• Goal is completeness
• Is more definitive, while the sketch approach is more explorative
• Used to describe a detailed design for a programmer to follow in
writing source code
• Notation should be sufficiently complete so that a programmer can
follow it in a straightforward manner
• Can be used by a designer to develop blueprint-level models that
show interfaces of subsystems or classes
– Developers then work out the implementation details
• As a reversed engineered product, diagrams convey detailed
information about the source code that is easier for developers to
understand
4
As a Programming Language
• Specifies the complete system in UML so that code can be
automatically generated
• Looks at UML from a software perspective rather than a conceptual
perspective which concentrates on the domain of study
• Diagrams are compiled directly into executable code so that the UML
becomes the source code
• Challenge is making it more productive to use UML rather than some
another programming language
• Another concern is how to model behavioral logic
– Done with interaction diagrams, state diagrams, and activity diagrams
5
Overview of UML Diagrams
UML 2.0: 12 diagram types
Structural Behavioral
: element of spec. irrespective of time : behavioral features of a system / business
process
• Communication(collaberati
on); Sequence
• Interaction overview
• Timing
3 basic building blocks of UML - Diagrams
Graphical representation of a set of elements.
Represented by a connected graph: Vertices are things; Arcs are relationships/behaviors.
5 most common views built from
UML 1.x: 9 diagram types. Behavioral Diagrams
Represent the dynamic aspects.
– Use case
– Sequence;
Collaboration
Structural Diagrams – Statechart
Represent the static aspects of a system. – Activity
– Class;
Object
Interction Diagrams
– Component
– Deployment
– Sequence;
Communication
– Interaction Overview
– Timing
7
Class Diagrams
Structural Diagrams
– Class;
Object
– Component
– Deployment
– Composite Structure
– Package
8
Class Diagram
The basis for all object modeling
All things lead to this
Most users of OO methods take an implementation perspective, which is a shame because the
other perspectives are often more useful. -- Martin Fowler
9
Classes
type/class
• A collaborator is also a class which the (current) class interacts with to fulfill a responsibility
Customer Account
Opens account Knows interest rate Manager
Account
Knows name Knows balance
Knows address Handles deposits
Reports fraud to
manager
11
Scope & Visibility
• Instance Scope — each instance of the classifier holds its own value.
• Class Scope — one value is held for all instances of the classifier (underlined).
Protected
class
singleton
multiplicity
1
NetworkController
3
consolePort [ 2..* ] : Port ControlRod
open()
close() dependency
generalization
association
ConsoleWindow DialogBox Control
generalization
Controller EmbeddedAgent
(multiple inheritance)
AudioClip
name
Microphone
record(m:Microphone)
start()
stop()
dependency Using relationship
CourseSchedule
Usually initial class diagrams will not have any significant number of dependencies in the
15
beginning of analysis but will as more details are identified.
Dependency – Among Classes
AbstractClass {abstract} <<metaclass>> <<interface>>
attribut MetaClassName InterfaceName
e
concreteOperation() operation()
abstractOperation()
<<instanceOf>>
generalization realization
ClassName
-simpleAttribute: Type = Default <<use>>
#classAttribute: Type
+/derivedAttribute: Type
+operation(in arg: Type = Default): ReturnType
<<instanceOf>>
16
Dependency –Among Classes
17
Dependency –Among Use Cases
• Two Stereotypes of Dependency Among Use Cases:
– extend: the target use case extends the behavior of the source
– include: the source use case explicitly incorporates the behavior of another use case
at a location specified by the source
System
Use Case A
Actor
<<include>> <<extend>> Order Processing System
<<actor>>
Place Order
Use Case B Use Case C
Actor <<extend>>
Extension points Request Catalog
Additional requests:
1 * after creation of The sales person
the order asks for the catalog
Structural Diagrams
– Class;
Object
– Component
– Deployment
– Composite Structure
– Package
19
Instances & Object Diagrams
“instance” and “object” are largely synonymous; used interchangeably.
difference:
instances of a class are called objects or instances; but
instances of other abstractions (components, nodes, use cases, and associations)
are not called objects but only instances.
Object Diagrams
very useful in debugging process.
– walk through a scenario (e.g., according to use case flows).
– Identify the set of objects that collaborate in that scenario (e.g., from use case
flows).
– Expose these object’s states, attribute values and links among these objects. 20
Instances & Objects - Visual Representation
anonymous instance
named instance
myCustomer
: Multimedia :: AudioStream
t : Transaction
: keyCode c : Phone
agent :
[WaitingForAnswer]
multiobject orphan instance
(type unknown) instance with current state
r : FrameRenderThread myCustomer
active object
(with a thicker border; owns a id : SSN = “432-89-1738”
thread or process and can initiate
control activity) active = True
instance with attribute values
21
Instances & Objects - Modeling Concrete Instances
• Expose the stereotypes, tagged values, and attributes.
• Show these instances and their relationships in an object diagram.
current: Transaction
primaryAgent <<instanceOf>>
[searching] LoanOfficer
current := retrieve()
: Transaction
1 : create
a: CallingAgent c: Connection
2: enableConnection 22
Instances & Objects – More Examples
1: sort() c : Company
list()
d: Directory contents: File
s : Department rd : Department
addFile(f:File) 1: addElement(f)
name = “Sales” name = “R&D”
d: Directory contents: File
Structural Diagrams
– Class;
Object
– Component
– Deployment
– Composite Structure
– Package
24
Component Diagram UML1.x – implementation view
loanOfficer.dll component
Registrar.exe
LoanOfficer CreditSearch
Course.dll
Student.dll
LoanPolicy
classes
25
Component Diagram UML2.0 – architectural view
26
Component Diagram – another example
(www.cs.tut.fi/tapahtumat/olio2004/richardson.pdf)
27
Component Diagram – another example
(www.cs.tut.fi/tapahtumat/olio2004/richardson.pdf)
28
Component Diagram – another example
(www.cs.tut.fi/tapahtumat/olio2004/richardson.pdf)
29
Component Diagram UML2.0 – architectural view
Explicit description of interfaces: lollipop
provided services to other components Component
requested services from other components
socket
An interface is a collection of 1..* methods, and 0..* attributes
Interfaces can consist of synchronous and / or asynchronous operations
A port (square) is an interaction point between the component and its environment.
Can be named; Can support uni-directional (either provide or require) or bi-directional (both provide and require)
communication; Can support multiple interfaces.
possibly concurrent interactions
fully isolate an object’s internals from its environment
caller or callee?
security AccessControl
StudentAdministration
Student Encription
Incoming
Persistence
signals/calls Outgoing
signals/calls 30
StudentSchedule DataAccess
Data[1..*]
Component Diagram: UML 1.x and UML 2.0
(http://www.agilemodeling.com/artifacts/componentDiagram.htm)
31
Component Diagram: UML 1.x and UML 2.0
(http://www.agilemodeling.com/artifacts/componentDiagram.htm)
a connector: just a link between two or more connectable elements (e.g., ports or
interfaces)
2 kinds of connectors: assembly and delegation. For “wiring”
An assembly connector: a binding between a provided interface and a required
interface (or ports) that indicates that one component provides the services required by
another; simple line/ball-and-socket/lollipop-socket notation
A delegation connector binds a component’s external behavior (as specified at a port)
to an internal realization of that behavior by one of its parts (provide-provide, request-request).
delegation
delegation
assembly store
connector
component or
class?
connector
Process loan
egb_server
membership_server
kernel32.dll
<<subsystem>>
Customer Service
component node
subsystem
Generalizable Element, Classifier, Class, Component? 36
Structured Class – Another Example
what kind?
37
Deployment Diagrams
Structural Diagrams
– Class;
Object
– Component
– Deployment
– Composite Structure
– Package
38
Deployment Diagram
J2EE Membership
Server Server
DecNet
Tomcat
Server
39
Structural Diagrams - Deployment Diagram
(http://www.agilemodeling.com/artifacts/deploymentDiagram.htm)
40
Structural Diagrams - Deployment Diagram
(http://www.agilemodeling.com/artifacts/deploymentDiagram.htm)
Is this better?
More concrete
Implementation-oriented
41
Types of nodes in deployment
• Device Node • Execution Environment
Node(EEN)
- It represent the physical - This is the software
computing device having computing resource
processor and memory. which typically executes
- It is responsible for on device node.
executing software - Following are choices of
system. EEN-
Eg: Bank Server, Computer, Database Engine, Web
mobile phone etc. Browser,WorkFlow
engine, Servlet container,
OS Software
Package Diagrams
Structural Diagrams
– Class;
Object
– Component
– Deployment
– Composite Structure
–Package
43
Packages
• Package — general-purpose mechanism for organizing elements into groups.
• Nested Elements: Composite relationship (When the whole dies, its parts
die as well, but not necessarily vice versa)
• (C++ namespace; specialization means “derived”)
• Packages that are friends to another may see all the elements of that package,
Visibility no matter what their visibility.
• If an element is visible within a package, it is visible within all packages nested
inside the package. 44
Dependency –Among Packages
• Two Stereotypes of Dependency Among Packages:
– access: the source package is granted the right to reference the elements of the
target package (:: convention)
– import: a kind of access; the public contents of the target package enter the flat
namespace of the source as if they had been declared in the source
Client
packageName + OrderForm
+ TrackingForm
- Order
<<import>> <<access>>
exports Policies <<import>>
packageName packageName
+OrderRules
-GUI:Window imports
subPackageName PackageClass GUI
<<import>>
+Window
+Form
#EventHandler
45
Modeling Groups of Elements
• Look for “clumps” of elements that are semantically close to one another.
• Surround “clumps” with a package.
• Identify public elements of each package.
• Identify import dependencies.
registration
Tools.db
db interfaces
Cloudscape Oracle
46
Class Package Diagrams
(http://www.agilemodeling.com/artifacts/packageDiagram.htm)
Seminar
Registration <<import>> Java
<<application>> Student Contact Infrastructure
Point <<technical>>
<<import>>
<<import>>
Professor <<import>>
• A frame depicts the contents of a package (or components, classes, operations, etc.)
• Heading: rectangle with a cut-off bottom-right corner, [kind] name [parameter]
Package Schedule
1..* 1 A frame encapsulates
Seminar Course a collection of collaborating instances or
refers to another representation of such
1 1..* held at
0..* 1
Location
Enrollment Time 47
Common Mechanisms
•Adornments
Notes & Compartments
•Extensibility Mechanisms
–Stereotypes - Extension of the UML metaclasses.
–Tagged Values - Extension of the properties of a UML element.
–Constraints - Extension of the semantics of a UML element.
48
Adornments
• Textual or graphical items added to an element’s basic notation.
<<library>> «subsystem»
Server accounts.dll AccountsPayable
{ dueDate = 12/30/2002
{channels = 3} {customerOnly} status = unpaid }
tagged values 51
Constraints
• Extension of the semantics of a UML element.
• Allows new or modified rules
• Rendered in braces {}.
– Informally as free-form text, or
– Formally in UML’s Object Constraint Language (OCL):
E.g., {self.wife.gender = female and self.husband.gender = male}
Corporation
Portfolio Department
BankAccount
{or} * *
{secure} {subset}
Person
BankAccount id : {SSN, passport} member 1..* 1 manager
A simple constraint Constraint across multiple elements Person
53
Classes: Notation and Semantics
Class - Name
responsibilities
• property-string
– leaf
– isQuery—state is not affected
– sequential—not thread safe
– guarded—thread safe (Java synchronized)
– concurrent—typically atomic; safe for multiple flows of control 56
Template Classes; Primitive Types
• A template class is a parameterized element and defines a family of classes
• In order to use a template class, it has to be instantiated
• Instantiation involves binding formal template parameters to actual ones, resulting in a concrete
class
template parameters
template class
Item
Value
Map Buckets : int
OrderMap
implicit binding Item Value Buckets
Is <<import>> transitive?
Is visibility transitive?
Does <<friend>> apply to all types of visibility: +, -, #?
58
Dependency –Among Objects
59
7. UML in the Software Process
Fitting UML into
Software Requirements Analysis
• A use case diagram helps describe how people interact with the system
• An activity diagram shows the context for use cases and also the details of
how a complicated use case works
• A class diagram drawn from the conceptual perspective is a good way of
building up a rigorous vocabulary of the domain
– It also shows the attributes and operations of interest in domain classes and
the relationships among the classes
• A state diagram shows the various states of a domain class and events that
change that state
61
Fitting UML into
Software Design
• A class diagram drawn from the software perspective can show design
classes, their attributes and operations, and their relationships with
the domain classes
• A sequence diagram helps to combine use cases in order to see what
happens in the software
• A package diagram shows the large-scale organization of the software
• A state diagram shows the various states of a design object and
events that change that state
• A deployment diagram shows the physical layout of the software
62
Fitting UML into
Software Documentation
63
Activity Diagram
Behavioral Diagrams
Represent the dynamic aspects.
– Use case
– Sequence;
Collaboration
– Statechart
–Activity
Activity Diagrams
• Model business workflows
• Identify candidate use cases, through the
examination of business workflows
• Identify pre- and post-conditions for use cases
• Model workflows between/within use cases
• Model complex workflows in operations on
objects
• Model in detail complex activities in a high
level activity diagram
Activity Diagrams
• Activities and Actions
• Transitions and Activity Edges
• Tokens and Activity Nodes
• Control Nodes
– Initial and Final Nodes
– Forks and Joins
– Decision and Merge Points
• States
• Swimlanes
Activity diagrams
• Useful to specify software or hardware system behaviour
• Based on data flow models – a graphical representation (with
a Directed Graph) of how data move around an information
system
[order reject]
Send Accept
Invoice Make Payment
Invoice Payment
67
Activities
• An activity is the specification of parameterized behaviour as the
coordinated sequencing of subordinate units whose individual
elements are actions
• Uses parameters to receive and provide data to the invoker
Activity
nodes
Parameter Activity Parameter Output
Input name
edges name
parameter Parameter parameter
name
69
Activity edges (1)
• Are directed connections
• They have a source and a target, along which tokens may flow
In this example we use a non-constant weight: an invoice for a particular job can
70
only be sent when all of its tasks have been completed
Control nodes – initial nodes
• In an activity the flow starts in initial nodes, that return the
control immediately along their outgoing edges
71
Control nodes – decision nodes
72
Control nodes – merge nodes
73
Control nodes – fork nodes
74
Control nodes – join nodes
75
Control nodes – final nodes
• Flow final:
– destroys the tokens that arrive into it
– the activity is terminated when all tokens in the graph are
destroyed
• Final node:
– the activity is terminated when the first token arrives
intentional race
between flows
76
Object nodes
• Hold data temporarily while they wait to move through the graph
• Specify the type of values they can hold (if no type is specified, they
can hold values of any type)
• Can also specify the state of the held objects
Behavioral Diagrams
Represent the dynamic aspects.
– Use case
–Sequence;
Collaboration
– Statechart
– Activity
Building a Sequence Diagrams
Sequence diagrams capture the use-case
behavior using the foundation of the classes.
Use Case 1
Class C
Class A
Use Case 3
Use Case 2
Class D
Class B
Diagram
Name p : Product : ShooppingCart
customer
display()
message
getPrice()
Lifeline
do (…)
create (…)
: Class3
Return Message
foo()
Messages to self
Object
Destruction
Illustration
Illustration
getPrice()
addProduct (p)
checkout ()
create (…)
: Order
sequence number
message name argument list
return value
asynchronousMessage
Return Message
check unknown
check ring
operate log
Example Example
check unknown
check ring
operate log
Example Example
opt
[msg.status=confirmed]
Condition
archive(msg)
Example
alt
[else]
wait()
Execution regions. At most
Else one will execute.
condition
(optional)
loop
Nested Loop
Fragment
isLooged = login(name,pass)
Do something …
Handy in model
exception
handling
login(name,pass) ref
Login Handling(user,pass) :
bool
Do something …
PRE-FUNCTION:
POST-FUNCTION:
• Conformation email sent accessing that authentication can be prevailed for the individual.
PRE-FUNCTION:
• Analyze the course of semester of logger.
POST-FUNCTION: