Software Design with UML
by Somboon Patntirapong
Course Overview
• Focuses on the Object-Oriented Analysis and Design (OOAD)
• Uses the UML as a tool for the OOAD modeling process
Software Requirements
• Java Runtime Environment (JRE)– Recommend Java SE DK 5
• Jude version 5 (UML Tool)
• Others UMLTools– ArgoUML, Poseidon, Visual Paradigm– IBM Rational, Borland Together, MagicDraw
Software Requirements
• References– Learning UML 2.0, Oreilly, Russ Miles, Kim Hamilton, 2006– Use Case Driven Object Modeling with UML—Theory
and Practice, Apress, Doug Rosenberg, Matt Stephens, 2007
– http://java.sun.com– www.omg.org
Course Outline
• Chapter 1: Introduction to OOAD and UML• Chapter 2: UseCase Diagram• Chapter 3: Activity Diagram• Chapter 4: Class Diagram• Chapter 5: Advanced Class Diagram• Chapter 6: Object Diagram• Chapter 7: Sequence Diagram• Chapter 8: Collaboration Diagram• Chapter 9: Component Diagram• Chapter 10: Deployment Diagram
Course Outline
• Chapter 11: Package Diagram• Chapter 12: State Diagram• Hand-on Case Study
Chapter 1
Introduction to OOAD and UML
Introduction to OOAD and UML
• Software Development Life Cycle– Requirements and Analysis
– Design
– Development
– Testing
– Deployment
Introduction to OOAD and UML
• Well-known Software Development Processes:– Waterfall
– Iterative
Introduction to OOAD and UML
• OOAD focuses on analysis and design phases– Use features of OO programing language
• UML as a tool (Modeling Language)– Why not model with code?
• What is Unified Modeling Language (UML)?– Notation
• Why UML?– Standard– Comprehensive and concise– Built on lessons learned
Introduction to OOAD and UML
• Degrees of UML– UML as a sketch– UML as a blueprint
• UML consists of diagrams:– UseCase– Activity– Class and Object– Sequence and Collaboration– State– Package– Component and Deployment
Chapter 2
UseCase Diagram
UseCase Diagram• Uses UseCase diagram to model the requirements• Is a starting point of project• Gives you a big picture• Shows who uses the system• Shows the features of the system
UseCase Diagram• Content Management System (CMS) case
• Requirement A1:The content management system shall allow an administrator
to create a new blog account, provided the personal details of the new blogger are verified using the author credentials database.
UseCase Diagram• Actor Element:
– Identifies who or what uses the use cases– Can be a person or a system
UseCase Diagram• Actor Element:
– Generalization/Specialization
UseCase Diagram• UseCase Element:
– Identifies required feature of the system
• Communication Line Element:– Connect an actor and a usecase
UseCase Diagram• System Boundaries Element:
UseCase Diagram• Requirement A2:
The content management system shall allow an administrator to create a new personal Wiki, provided the personal details of the applying author are verified using the author credentials database
UseCase Diagram• <<include>> Element:
– Incorporates behavior
UseCase Diagram• Special Case/Generalization Element:
UseCase Diagram• <<extend>> Element:
– Not always, might or might not
Chapter 3
Activity Diagram
Activity Diagram
• UseCase diagram show what your system should do• Activity diagram show how your system will
accomplish it goals• Shows a procedure or workflow• Similar to flowchart
Activity Diagram
• Initial Node Element:– Starts the activity
• Action Element:– Actions are the active steps in the activity
Activity Diagram
• Flow Element:
• Final Node Element:
Activity Diagram
• Decisions and Merges Element:– Guard : [condition]
Activity Diagram
• Fork and Join Element:– Fork : simultaneous flow– Join : all incoming action must finish before proceed to the
next flow
Activity Diagram
• Object Node Element:– Objects can be passed between actions
Activity Diagram
• Signal Element:– Activity may involve external systems, people, or processes– Eg: authorizing credit card payment– Sending :– Receiving :
Activity Diagram
• Swimlane/Partition Element:– Used to differentiate the participants– Or to group the actions
Activity Diagram
• Case Flow:– The administrator asks the system to create a new blog
account– The administrator selects an account type– The adminstrator enters the author’s details– The author’s details are verified using the author credentials
database– The new blog account is created– A summary of the new blog account’s details are emailed to
the author
• Draw your own one!!
Activity Diagram
Chapter 4
Class Diagram
Class Diagram
• Class diagram shows the classes that you must have to create a system
• So, what is a class?– Class is a blueprint of object
• Program must have at least one class• But normally more than one class (may be a
thousand)• What can the class contain?
– Attributes (Instance Variables)– Operations (Methods)– Constructors
Class Diagram
• Class Diagram:
Class Diagram
• Source code:public class Account{
private double balance;
public Account(double intiBalance){ balance = initBalance; } public boolean deposit(double amt){ .. } public boolean withdraw(double amt){ .. }}
Class Diagram
• Visibility– Private (-)
– Package (~) ( )
– Protected (#)
– Public (+)
• Note:– For Java, protected = package + subclass
Class Diagram
• Class Attributes:– Inline
– Association
Class Diagram
• Multiplicity:– 1 .. 1– 1 .. *– * .. 1– * .. *
Class Diagram
• Attribute Properties
• Source code:
public class CMS{ private final String createdBy = “James & Co..”; ..}
Class Diagram
• Class Operations:
Class Diagram
• Information Hiding– To protect our valuable information (data)– How?
• Encapsulation– We separate the system into many clasess (OO)– BUT each class has protected his own data!!– So, what should we do?
Class Diagram
• Information Hiding/Encapsulation– Can’t apply these concept separately– Otherwise useless!!
Class Diagram
• Static Members:
Chapter 5
Advanced Class Diagram
Advanced Class Diagram
• Classes can have relationships to one another• A class can be a type of another class; generalization• A class can contain objects of another class in
various way
• Class relationship:– Dependency (weakest)– Association– Aggregation– Composition– Inheritance (strongest)
Advanced Class Diagram
• Dependency– Dependency between two classes means one class needs
the other class– One class USES another class– Let say, A depends on B– If B changed, A needs to know the changes!!– If A changed, B doesn’t care
Advanced Class Diagram
• Source Code:
Public class UserInterface{ .. public void main(String args[]){ BlogEntry be = new BlogEntry(); be.setName(“My first blog”); .. }}
Advanced Class Diagram
• Association:– Means that a class will contain a reference to an object of
the other class– In form of an attribute– Relationship stronger than dependency
Advanced Class Diagram
• Source code:
public class BlogAccount{ private BlogEntry[] entries; ..}
public class BlogEntry{ ..}
Advanced Class Diagram
• Association with direction:– Can be unidirection– Or can be bidirection
Advanced Class Diagram
• Association class:– Resolves complex relationship (Many-to-Many)– Depends on object model
Advanced Class Diagram
• Aggregation:– Is just a stronger version of association– Owns but may share object of another class– Owned object may have a lifetime outside the owning object– Deletion of Project doesn’t imply that Employee must be
deleted
Advanced Class Diagram
• Source code:– For java, association and aggregation, coding is not different
public class Project{ private Employee[] emps; ..}
public class Employee{ ..}
Advanced Class Diagram
• Composition:– Kind of aggregation– But stronger than aggregation– Implies that owned objects can’t live without owning object– Eg, Introduction and MainBody don’t have meaning without
BlogEntry
Advanced Class Diagram
• Source code:– Association, Aggregation, and Composition, coding is the
same
public class BlogEntry{ private Introduction intro; private MainBody body; ..}
Advanced Class Diagram
• Generalization:– Inheritance– Is-A relationship or Kind-of relationship– Support multiple inheritance, but beware of conflicts
Advanced Class Diagram
• Source code:
public class Article{ ..}
public class BlogEntry extends Article{ ..}
Advanced Class Diagram
• Abstract Classes:– Classes that define functionality without providing full
implementation– Therefore can not be instantiated– Any class that extends an abstract class must implement
abstract method
Advanced Class Diagram
• Class that extends abstract class:
Advanced Class Diagram
• Source code:
public abstract class Store{ public abstract void store(Article[] articles); public abstract Article[] retrieve();}
public class BlogStore extends Store{ public void store(Article[] article){ .. } public Article[] retrieve(){ .. }}
Advanced Class Diagram
• Interface:– Like class that everything is abstract– Is not for extending, but for implementing– Avoids the problem of multiple inheritance– Methods listed in an interface are all abstract
Advanced Class Diagram
• Class that implements interface:
Advanced Class Diagram
• Source code:
public interface EmailSystem{ public abstract void send(Message msg);}
public class SMTPMailSystem implements EmailSystem{ public void send(Message msg){ .. }}
Chapter 6
Object Diagram
Object Diagram
• Objects are runtime representation of classes• Objects can be called Instances• Object diagram is very similar to a class diagram• Is useful when you want to describe how the objects
within the system work
Object Diagram
• Object can contain/show data:
Object Diagram
• Links:
Chapter 7
Sequence Diagram
Sequence Diagram
• Is a kind of interaction diagram• Shows interaction between parts of your system• Or identifies the objects involved with each process• Focuses on time sequence• One sequence relates directly to one usecase• You will know how well design of you classes with the
sequence diagram
Sequence Diagram
• Participants and Time Lines:– Usually the object– But can be an external system or people
Sequence Diagram
• Messages and Activation Bars:– Invoking methods/operations
Sequence Diagram
• Nested Messages:
Sequence Diagram
• Synchronous Messages:– Waits for response
Sequence Diagram
• Asynchronous Messages:– Don’t wait for a response– Eg, threading, messaging
Sequence Diagram
• Creation and Destruction Messages:
Sequence Diagram
• Creation Messages:– In Java, using new keyword– Eg, new Account(500);
• Destruction Messages:– In Java, doesn’t have to destroy object– Use garbage collector– So, check your preferred language– Implies no use of destruction message!!
Sequence Diagram
• Back to CMS case• Main flow:
– The administrator asks the system to create a new blog account
– The administrator selects the regular blog account type– The administrator enters the author’s details– The author’s details are checked using the author credential
database– The new regular blog account is created– A summary of the new blog account’s detailss are emailed to
the author• Just for review, because we already have the activity
diagram
Sequence Diagram
• Top-Level Sequence Diagram:
Sequence Diagram
• Detailed Sequence Diagram:– Contain more participants, more precise– But too much details may make the diagram complicated– Details may be the actual user interface of your choice
Sequence Diagram
Chapter 8
Collaboration Diagram
Collaboration Diagram
• Another kind of interaction diagram• Alternative to sequence diagram• Objects are concerned with numbered arrows
showing the flow of information• Focuses on link perspective• Called communication diagram in UML 2.0
Collaboration Diagram
• Participants, Links, and Messages:– Participants: objects, people, systems– Links: relationship– Messages: invoking methods (operations)
Collaboration Diagram
• Nested Messages:– The called method invokes others methods
Collaboration Diagram
• Invoking message multiple times:– Format: [i=0..9]
Collaboration Diagram
• Sending a message based on a condition:– Format: [condition=true]
Collaboration Diagram
• Back to CMS Case– Collaboration vs Sequence Diagrams
Collaboration Diagram
Collaboration Diagram
• Collaboration VS Sequence Diagrams– What do you think?– Which one do you prefer?
• Sometimes we need both!!
Chapter 9
Component Diagram
Component Diagram
• Component is a reusable part of your software• Eg, libraries
• Component diagram shows:– Packaging of code– Dependencies between components– Can show nested components
Component Diagram
• A basic component:
• Provided and Required Interfaces:
Component Diagram
• Using stereotype notation:– If you want to show the details of interfaces
Component Diagram
• Components working together:– Components usually work together with other components
Component Diagram
• Dependency:– Component depends on other components
Component Diagram
• Artifacts:– Can be libraries– In Java, JAR Files
Chapter 10
Deployment Diagrams
Deployment Diagram
• Shows the physical view of your system• Shows the physical relationships between hardware
components• Shows components within the nodes• Shows the protocol being used between nodes
Deployment Diagram
• Nodes:– Can be systems:– Eg, Application Server, Web Server, Operating System– Can be hardwares:– Eg, Server, Desktop PC
Deployment Diagram
• Communications:– Shows connection with protocols
Deployment Diagram
• Showing components:– Shows components that are deployed in the node
Deployment Diagram
• Node Instances:
Chapter 11
Package Diagrams
Package Diagram
• Used to grouping items especially classes• Also provides namespaces• Helps member visibility
• How good is system without packages?
Package Diagram
• Packages:– Like folder icon– In Java, directories
Package Diagram
• Contents of a package:– Usually classes– Nested packages, finally classes inside
Package Diagram
• Source Code:
package security;
public class Credential{ ..}
Package Diagram
• Showing class with its package (an alternative)
Package Diagram
• Package Dependency
Chapter 12
State Diagrams
State Diagram
• Shows how one object changes over time• Helps understanding of the model• What shoud do/what should not do• Consists of:
– State– Event
• State diagram is heavily used in niches of software such as:– Embedded System– Real-time System
State Diagram
• States:– Status of being at a certain time– Eg, light: on/off
State Diagram
• Transitions:– Represents a change of states from a source state to a
target state– Event/Trigger makes transition
State Diagram
• Complex Transitions:– Contains conditions or guards
State Diagram
• Internal Transition/Action in State:– Entry, Do, Exit
State Diagram
• Initial and Final State:– Starting and ending points
Software Design with UML
• What next?– Design pattern– GoF Design pattern– Enterprise pattern
• Hopefully, you like UML• Enjoy your drawing!!
Thank You,Somboon Patntirapong
Copyright 2007