You are on page 1of 116

OOAD

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 1
Objective
‹ To understand the Object Oriented way of approaching a
problem and to understand the modelling of Object
orientation using UML
‹ To gain a good knowledge of using UML for designing
projects following Object Oriented Approach
‹ To use Magic Draw tool to draw diagrams of UML

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 2
Agenda
‹ (00:20) Introduction to modelling

‹ (00:30) Intro to UML, Magic Draw

‹ (00:20) OO Analysis, Noun Phrase Approach, CRC cards

‹ (00:15) Break

‹ (00:30) Requirement Analysis

‹ (01:30) Use case Diagram / Specification

‹ (01:00) Lunch Break

‹ (01:15) Class Diagram

‹ (00:15) Break

‹ (02:00) Sequence Diagrams, State Transition Diagrams

‹ (01:15) Working with magic Draw UML


Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 3
Software Complexity

‹ Required to perform demanding tasks


‹ Complexity of Problem Domain
‹ Difficulty in managing development process
‹ Flexibility available through software
‹ Problems of characterizing behaviour of discrete systems

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 4
Resolution for complexity

A complex system that works is invariably found to have


evolved from a simple system that worked.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 5
Two Methods of Decomposition

‹ Algorithmic Decomposition

Programs={Data Structures}+{Operations}

‹ Object-Oriented Decomposition

Object={Data Structures}+{Operations}

Programs=Objects

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 6
Algorithmic Decomposition / Functional
Decomposition

‹ Defining the how and what of the goal

‹ Specifying and decomposing system functionality

‹ Decomposing each task into smaller tasks

(to the level of language statement)

‹ Implementing the program and the steps that compose


each function

‹ Extensive restructuring necessitated by changes in


requirements.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 7
Example of Algorithmic Decomposition

For a Railway Reservation System, some of the following

functionalities can be identified

„ ReserveTicket()

„ cancel reservation()

„ AddtrainDetails()

„ View_waitingList() e.t.c

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 8
Object-Oriented Decomposition
‹ Decomposing a system into objects, the basic
components of the design

‹ Finding or creating these objects by structuring of


knowledge and activities

‹ Managing the complexity inherent in the real world


problem by abstracting out knowledge, and
encapsulating it within objects

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 9
Example of Algorithmic Decomposition

We identify the real world objects invloved in the railway

reservation system.some of the objects involved could be

„ Passenger

„ Train

„ Ticket e.t.c

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 10
Advantages of Object-Oriented Decomposition
‹ Better understanding of the system.

‹ Combines data and behaviour into one package - the object.

- Separate development teams can work independently.

‹ Avoids duplication of common behaviour - inheritance.

- New kinds of objects can be added later without harm.

‹ Permits iterative development of large systems.

- Reduced risk of building complex software systems.

‹ Easy to Maintain.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 11
Where OO can be used?

OO is most relevant in business area that are:

‹ Rapidly changing

‹ Require fast response to changes

‹ Complex in requirements or implementation

‹ Repeated across company with variations

‹ Have long-lived applications that must evolve

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 12
Object - Definition

A real world entity.

An object has state, behaviour and identity;the structure and


behaviour of similar objects are defined in their common
class.

The term object and instance are interchangeable.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 13
Object - State

Encompasses all of the properties of the object and the current


value of these properties.

Attributes(static) and their values(dynamic).

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 14
Object - Behaviour

How an object acts and reacts, in terms of its state changes


and message passing.

An object can acts on other objects and is also acted upon by


other objects

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 15
Object - Identity

It is that property of an object that distinguishes it from all


other objects.

The unique identity of each object is preserved over the


lifetime of the object, even when its state is changed.

“is the river the same river every day, even though the same
water never flows through it??”

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 16
What is your view about class and object?

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 17
Object-Doughnut notation

Methods

Data

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 18
Elements of Object Model - Class

A set of objects that share a common structure(attributes) and


behaviour(operations).

A mould with which objects can be created.

Look for class in…

Tangible things - Cars, Books …

Roles - Student, Employee …

Events - Driving, Landing …

Interactions - Loan, Account …

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 19
Class & Objects

objects Object
References

redRose

class Rose blueRose

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 20
Difference between Class and Object

Class Object
Class is a type/template for Object is an instance of the
similar objects class, with each instance
behaving identically

Class is purely a static Object is dynamic/run-time


concept, represented by entity,occupying space in
program text memory

Rock Musician Alice Cooper

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 21
Implementations – Java Syntax for Class

class classname
{
//member variables
datatype membername;

//methods
returntype methodname()
{
:
}
}

class is a keyword. lowercase


Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 22
Implementations - Java

class Account class Book {


{
int id; int bookId;
double balance; double price;
void open() { }
void close() { } void changePrice() {
void credit() { } }
}
}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 23
Implementations – Java Syntax for Object

To create an object of Account class

Account acc = new Account();


(or)
Account acc;
acc = new Account();

‘acc’ is like a pointer.


In java it is called a reference variable.

new is operator and keyword


Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 24
Object Oriented Analysis

How to identify classes:


Look for noun phrases
-Change all plurals to singular
-Retain the obvious ones and those you are not sure of
-Discard obvious nonsense

Look for hidden nouns

Define Relationships
- create Hierarchies

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 25
Object Oriented Analysis

Extract responsibilities from requirements specification by


looking at verbs & Information.

To find Collaborations, ask:


- With whom does this class need to collaborate to
fulfil its responsibilities?
- Who needs to make use of the responsibilities defined
for this class?

Identify Sub-systems
Grouping of logically similar systems.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 26
CRC – Class-Responsibility-Collaboration cards

Introduced by
Ward Cunningham & Kent Beck,
Tektronix Research Lab.

Class Name

Responsibility Collaboration
Extract responsibilities With whom does this class 4”
from requirements need to collaborate to
specification by fulfil its responsibilities?
looking at verbs Who needs to make use of
& Information the responsibilities
defined
for this class?

6”
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 27
CRC – A Sample

Grade

1.Calculate the grade of a Student


student. Course
2..

3 ..

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 28
How to identify classes?

Noun phrase identification -> candidate classes.

Refine candidate classes -> actual classes.

Preferred abstraction is Entity Abstraction.

Look for…
Tangible things
Roles
Events

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 29
Class

Candidate Class

Initial Set of real world Objects that are identified which

has the possibility of becoming a class in the System

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 30
What are the Principles of the Object Oriented
Model?
Major Themes
(mandatory elements for any OOM):
Abstraction
Encapsulation
Modularity
Hierarchy
Polymorphism

Minor Themes
(useful but not essential part of OOM)
Typing
Persistence

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 31
Abstraction

Definition:

An abstraction denotes the essential characteristics of


object that distinguishes it from all other kind of objects
and thus provide crisply defined conceptual boundaries
relative to the perspective of the user.

Example:

Building seen by an architect and layman.


TV seen by a mechanic and a customer.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 32
Encapsulation

Abstraction focuses upon the observable behavior of an object,


whereas, encapsulation focuses upon the implementation that
gives rise to this behavior.

Encapsulation is achieved through information hiding .

Example: Capsule, Iron Box

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 33
Implementation of Encapsulation

Access specifiers

Public

Private

Protected

Default

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 34
Implementation of Encapsulation

class Book
{
private int id;
private string name;

public void addBook() { }


public void viewBook() { }
public void checkAvailability() { }
}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 35
Modularity

Modularity creates a number of well-defined, documented


boundaries within a system.
A module typically clusters logically related abstractions.
Enhances understandability of the system.

Abstractions classes

A module package
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 36
Hierarchy

Hierarchy is a ranking or ordering of abstractions.

The important hierarchies in an object oriented system are:

‹ Inheritance or class structure hierarchy


‹ Aggregation or object structure hierarchy

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 37
Inheritance

Name
Person age

Employee Id
Salary
Department

Overcomes the disadvantage of Redundant Code


Advantage: Reusability of Code

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 38
Inheritance

Represents “is a” or “ is a type of” relationship between


two classes. Features that are common to many classes
are migrated to a common class, called base class, (or
super-class, or parent class).
Other classes may add,modify, or even hide some of
these feature. These are called as derived classes, (or
sub-classes, or child classes).
For example:
Vehicle can be a base-class and car and bike can be
derived classes.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 39
Implementation of Inheritance

class Person
{

class Employee extends Person


{
//Need not repeat features
(data+methods) inherits
}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 40
Types Inheritance

Multiple Inheritance (not allowed in java at class level)

Multilevel Inheritance possible Person


class Person { } Employee
class Employee extends Person { }
Manager
Class Manager extends Employee { }

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 41
Aggregation

Represents the “is a part of” or “whole-part” relationship


where one object becomes a part of other object.

Example: Car
Engine (is a part of a car)

Computer
Keyboard (is a part of computer)

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 42
Polymorphism

An operation behaving differently in different contexts.

Same Entity Student

Son / Daughter

Employee

Girl Friend / Boy Friend

Husband / Wife

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 43
Implementation of Polymorphism

Compile Time
Method Overloading (Ad-hoc Polymorphism)
Example: void swap(int, int)
void swap(char, char)
void swap(float, float)

Can I Have?
cannot be overloaded based on
void swap(int,int) return type
int swap(int, int)

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 44
Polymorphism

Runtime Time class Account


{
public void showBalance()
Method Overriding {
}
}
class CurrentAccount extends Account
{
public void showBalance()
{
}
}
class SavingsAccount extends Account
{
public void showBalance()
{
}
}
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 45
Implementation of Abstract Class

abstract class Shape Shape s=new Shape();


{ (not possible)
abstract public void draw();
} Shape s=new Circle();
class Circle extends Shape s.draw(); //draws Circle
{
public void draw() s=new Rectangle();
{ s.draw();//Draws Rectangle
//draw Circle
} The entity is one and same and the
class Rectangle extends Shape method is also same but in different
{ situations it gives different output.
public void draw() This is called polymorphism
{
//draw Rectangle When all methods in a class are abstract
} the class is converted into an interface
}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 46
Minor Themes - Persistence

Persistence:

Is the property of an object through which its existence


transcends in time.(i.e. Object continues to exist after its
Creator ceases to exist) and/or space.(i.e Object’s location
moves from the address space in which it was created.)

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 47
Minor Themes - Typing

Typing:

Is the enforcement of the class of an object, such that objects


of different types may not be interchanged, or at the most, they
may be interchanged only in restricted ways.

Examples of Typing: Strongly Typed and Weakly typed

A given programming language may be strongly typed,weakly


typed or even untyped, yet still can be called Object oriented.
Eiffel – Strongly Typed, Smalltalk – untyped, c++ - hybrid

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 48
Minor Themes - Typing

Static or early binding means that the types of all variables and
Expressions are fixed at the time of compilation.

Dynamic binding or late binding means that the types of all


variables and expressions are not known till runtime.

Strongly typed languages require the type checking of all


arguments,receivers and return types at compile time.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 49
Object Oriented Analysis and
Design
As the name suggests it is one of the approaches to solve a problem
where modelling is done on the basis of real world objects.

So we have to model. But what is a model?

Definition:
A model is a simplification (or) representation of reality.

A model provides you a blueprint of the system to be constructed.

Ex: Even before constructing a house the architect builds a


model and shows you.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 50
Model – Why? and Aims

But why?
‹ We build models so that we can understand the system
‹ We are building, better.
‹ Model complex systems to narrow down the problem view.
‹ To comprehend a systems in its entirety.

Through model we achieve …

‹ Models help us to visualize system.


‹ Models permit us to specify the structure or behaviour of a system.
‹ Models give us a template that guides us in constructing a system.
‹ Models document the decisions we have made.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 51
OOAD and UML

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 52
Modelling Language
A modelling Language is one which is used to analyse the
system better.(not a programming language as it is used to
Solve the problem).

Object oriented modelling is where you model the system


using objects.

OOM Languages(1970 –1980)


Booch Method - Booch(Design and Construction oriented)
OOSE – Jacobson (Use case oriented)
OMT – Rumbaugh (Analysis oriented)
Fusion – Shlaer & Meller

Each had its own strengths and weaknesses.


Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 53
What is UML?

‹ UML is a Language for Specifying, Visualizing,


Constructing, and Documenting Software Artifacts

‹ What Does a Modelling Language Provide?

‹ Model Elements: Concepts and Semantics

‹ Notation: Visual Rendering of Model Elements

‹ Guidelines: Hints and Suggestions for Using Elements in


Notation.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 54
Building blocks of UML

Things Relationships Diagrams


Association Use case
Dependency Class
Gen/Spec Object
Realization Interaction
Sequence
Collaboration
Structural Behavioural An notational Grouping [Communication]
Class Message Note Package Activity
Interface State State Chart
Use case Component
Active Classes Deployment
Node

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 55
Architecture and the UML

Design View Implementation View

Class & Object


Component
Use Case
Use Case View

Process View Deployment View

Interaction, Activity & State chart Deployment

Conceptual Physical
Package, subsystem Interaction
State machine
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 56
A Road Map . . .

Activity

Use case Class Interaction Component

Deployment

Textual Usecase State Chart


CRC

UML Diagrams
Not Part Of UML
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 57
Use Case Diagram

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 58
Use-Case Diagrams

‹ Describes “what” the system does


‹ Interaction of Users with System Components
‹ Graph of Actors and Set of Use Cases Enclosed by
System (High-Level) or Class Boundary
‹ Focus on What Actions, Methods, Functions, etc. are
Utilized by Which Actors
‹ Black Box View of System Components
‹ Derived via User Interviews
‹ Granularity Level of Use-Cases is Variable

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 59
Use case Diagram – Actor

Definition:
An actor is someone or something outside the system that
interacts with the system.

It is a role, like Faculty(not the person - Jack).

An actor is external – it is not actually part of what we are


building , but an interface needed to support or use it.
It represents anything that interacts with the system.
Notation
<<actor>> Stereotype
{OR}
Bank System
Actor Name
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 60
Use case Diagram – Use case

The use case diagram presents an outside view of the system


The use case model consists of usecase diagrams.

Usecase Notation
Name of the usecase

Usecase name - Meaningful verbs or short verb phrases.

Usecase- A Sample
Add Student Details

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 61
Supermarket Example

TheStore The Store: System View


Scan Items

Process Order

Buy Items Customer


Cashier
Catalog
Check Status

Sales Person
Place Order

Customer Fill Order

Catalogue: Class View Estb. Credit


Supervisor
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 62
Use case Diagram – Relation - Include

Three important types of relations used in usecase diagram


Include
The include relationship shows that the base use case explicitly
includes (uses) the behaviour of the included use case.
The included use case does not have a role by itself.

<<inclu
Track Order de>>

Validate User
lude>>
c
<<in
Place Order

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 63
Use case Diagram – Relation - Extend

Extend – An extend relationship shows optional behaviour

Return book <<extend>>


Calculate penalty
• On Late Return

Extension point

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 64
Use case Diagram – Relation - Generalization
Generalization
Use cases can inherit from other use Academic Clerk

cases, just like classes.


Actors participating in a system can
be inherited from an existing actor.

Validate Course Academic Supervisor

Validate UG Course Validate PG Course


Registration Officer

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 65
Use case Diagram – SMPS

c lu de>>
<<in

Registration Officer

System Boundary
Academic Supervisor

<<extend>>
Academic Clerk

SMPS
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 66
Textual Use case [Use case Specification]

Textual Use case involves describing its primary


scenario as a sequence of numbered steps and the
alternatives as variations on that sequence.
Usecase name
Actor Involved.
Basic flow of Events
1.
2.
.
.
Alternative : Name
At step: step #, description.
“What to do now?”
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 67
Textual Use case – A Sample

A scenario: The customer browses the catalogue and adds desired items to
the shopping cart. When he wishes to pay, he describes the shipping and card
information and confirms sale. The system checks the authorization on the
credit card and confirms the sale both immediately and with a follow-up email..

Buy a Product
Actor: Customer
1 Customer browses the catalogue and selects items to buy.
2 Customer fills in shipping information.
3 System presents full information, including shipping.
4 Customer fills in credit card information.
5 System authorizes purchase.
6 System confirms sale immediately
7 System sends conformation email.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 68
Textual Use case – A Sample
Alternative: Authorization failure
At step 5,system fails to authorize credit purchase
Allow customer to re-enter credit card information.
Go to step4

Alternative: Regular Customer


3a. System displays current shipping information,
pricing information and last four digits of credit
card information.
3b. Customer may accept or override these information
Return to primary scenario at step 5.
Try it for
1.Return of a book.
2.issue of a book
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 69
CLASS

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 70
Class - Elided
A class is a the framework for set of objects, which share
the same attributes, operations, relationships and semantics.
Also known as classifier.
Notation:
Every class has a name. A name can be simple, where in
only the name of the class is specified.
Class Name
Elided class notation
Samples

Student

smps::Student

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 71
Class - compartmentalized

A complete class notation.


Student

Class Name studentID


studentName
Attributes of a Class stream
addStudent()

Methods of a Class validateStudentID()

deleteStudent()

InvalidSIDException
Exceptions

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 72
Class - Attributes

A attribute is a named property of the class. The attributes of a


class characterize the class. Attributes specify a range of values
that the objects of the class may hold.

The syntax for specifying the attribute is

[visibility] name [multiplicity] [: type][ = initial value] [{property string}]

Visibility is the scope of the attribute.


It could take the following values:
- : for private
+ : for public
# : for protected
~: for default

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 73
Class - Attributes

Property string could be .

Frozen – cannot be changed (constant or final)

addOnly – only with multiplicity

changeable – by default

Example: - employeeName [0..1] : String = “Ramya” {frozen}


Attribute name starts with lowercase. Subsequent word
uppercase.

Property string {frozen, addOnly, changeable}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 74
Class – Operations

Property string :
isQuery – operation does not have any side effects.
Parameter list can have
[direction] name : type [=default value] or [data type] name:type

Employee

+ setEmployee( e : Employee)
+ getEmployee():Employee {isQuery}
+ initializeID(in IDNo :integer=100)

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 75
Responsibilities

‹ Responsibilities are obligations to be fulfilled by a class.


‹ The Student class, for example is responsible for adding a

new student to the database.


‹ Responsibilities are shown in textual form, in simple English.

Employee

-Add new employee


-Modify employee details
-Validate employee
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 76
The Class Diagram

Employee

<<basic details>>
- empId : Integer
- empName : String
- dateOfBirth : Date
<<employee details>>
- salary : double = 1000.00
- deptName : String
<<Getter>>
+ getEmpId() : Integer
<<Setter>>
+ setEmpId(id : Integer)
Responsibilities
- maintain employee details
- determine employee age
- setting employee details
Exceptions thrown
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 77
Relationships

Relationships connect two or more things. In object orientation


its connections between two elements.

There could be six types of relationship among classes.


They are
1.Association
2.Inheritance or Generalization
3.Aggregation
4.Composition
5.Dependency
6.Realization

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 78
Association

The association relationship is a simple relationship. It connects


two classes , denoting the structural relationship between them.
An association is shown as a line connecting the related classes.
Example:

works for /has


Manager Company
Employee Employer

We can also show how many objects may be connected for an instance
of an association relationship. This is called as multiplicity.
It defines how many objects participate in relationships.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 79
Multiplicity

Multiplicity can be expressed as

Exactly one - 1
Zero or one - 0..1
Many - 0..* or *
One or more - 1..*
Exact Number - e.g. 3..4 or 6
Or a complex relationship - e.g. 0..1, 3..4, 6..* would
mean any number of objects other than 2 or 5

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 80
Multiplicity – Examples

School has one or more Departments.

1 has
1..*
school department

Instructors can teach up to 3 subjects.


The same subject can be taught by different instructors.

teaches
1..* 1..3
instructor subject

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 81
Association Class
we can also show an association class in an association
relationship. An association class is one that makes it
possible for the association to exist between two other
classes.

1..* transacts with 1.. *


Member Book

Transaction

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 82
Inheritance or Generalization

Generalization consists of the super class and sub-class relationship.


The super class represents a general concept while the sub class
represents a more specific concept. Also called as “ is a type of ”.

Examples:

Rose is a type of flower.

Quick sort is a type of sorting algorithm.

Pen is a kind of writing instrument.

Windows is a kind of operating system.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 83
Inheritance or Generalization – Example

Operating System

Windows Linux Solaris

The arrow heads will point towards the super class.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 84
Aggregation

The class at one end of the relationship will contain classes at the other
end of the relationship. It is also called a whole part relationship.
Signifies the “part of” or “has a” relationship.

Examples:

A room has a door.


Building has rooms.
Vehicle has an engine.
Company has departments
Book has chapters.

Two forms of Aggregation:


Simple Aggregation
Composition
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 85
Aggregation

FourWheeledVehicle

4 2..5

Door Seat

It doesn’t link the life time of the whole and its parts. An aggregation
is shown by a diamond next to the class representing the whole
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 86
Composition – a special form

It is also “part of ” relationship only but if the whole ceases to


exist, the parts automatically cease to exist.

1
Building Roof

Is shown by a filled diamond next to the class representing the whole.

Circle Point Circle

Point
Polygon

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 87
Dependency

Is the “using” or “uses” relationship where one element is


using another element to get its task done. A change in
one element affects the another element that uses it. i.e.
if the one changes then it affects the other element. The
reverse need not be true.
Example

Payroll
Employee
Generator

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 88
Realization

The relationship between the class and the interface.

Interface :
An interface is formally equal an abstract class with no
attributes and methods(implementations ), only abstract
Operations.

(or) <<interface>>
Interface Name
Interface Name

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 89
Realization

ICICIBank <<interface>>
Bank

ICICIBank

Bank

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 90
Class Diagram

A class diagram is a diagram that shows a set of classes,


Interfaces and collaborations and their relationships.

Elements of Class Diagram

Class
Interfaces
Relationships between them
Notes and Constraints.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 91
Adornments

Adornments are common mechanisms that enhance the


understanding of the system.

The adornments are:


Note
Tagged Value
Stereotype
Constraint

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 92
Notes

A note lets us specify comments about a particular aspect


of a model.
A note is graphically shown as a rectangle with a folded corner.
It also contains textual or graphical comments.

9
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 93
Tagged Values

Tagged values allow us to create new information in the specification of


an element.

This is represented as a string placed between a pair of curly braces {…}

Tagged values are placed below an element.

Example:
{version=1.3}
{author=Steve}
{date=27/11/2007}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 94
Constraint

Constraints are rules, not just information.

This is represented as a string placed between a pair of curly braces {…}


Located in the close proximity to the element.

Example:

{runs only on the last day of the month}

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 95
Stereotypes

Typically stereotypes are enclosed within double angular


brackets ,<< >> .

The content inside the brackets are predefined.

Example:

<<extend>>
<<include>>

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 96
The real world scenario

Objects in real world are not static. There are very dynamic and they
communicate by messages.

In software, so far we have one view of system design, i.e., static or structural
view. It is impossible to capture all details of a complex system through just
one view.The structural modelling of UML is largely static.

We depict the abstractions and the objects that are created out of these
abstractions, in the structural model. UML provides dynamic modelling of
elements.Dynamic modelling is also refereed as behavioural modelling.

Some of the dynamic events are:


‹ Creation of objects
‹ Destruction of objects
‹ Sending messages between objects(object interactions)
‹ Capturing the current state of an object
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 97
Interaction Diagram
Interaction Diagrams

Sequence Diagram Collaboration Diagram

An interaction diagram shows an interaction including the messages that may


be dispatched among them.

A sequence diagram is an interaction diagram that emphasizes the time


ordering of messages.

A collaboration diagram is an interaction diagram that emphasizes the


structural organization of the objects that send and receive messages.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 98
A First Look at Sequence Diagrams

Illustrates how objects interacts with each other.

Graphically a sequence diagram is a table that shows objects arranged


along X axis and messages, ordered in increasing time, along the Y axis.

Can model simple sequential flow, branching, iteration,


and concurrency.

Elements:
Objects
Messages
Lifeline
Activation Box (or) Focus of Control
Notes and Constraints(Like all other diagrams)
Actor
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 99
Lifeline &Activation Box (or)Focus of Control

Whenever we invoke a method or whenever any activity is


carried out the method is active.
Every object will have
Object symbol
name : Class a lifeline, which shows
when the object is
Lifeline
created or when it will
be destroyed.
Activation Box
The Lifeline represents
the object’s life

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 100
Messages

A message is one that goes from one object to another, goes from
one object’s life line to other object’s lifeline.

A message can be synchronous or asynchronous.

Synchronous message: If an object sends a synchronous


message, it waits for an answer to that message before it
proceeds with its business

Notation
or

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 101
Messages

Asynchronous message: If an object sends an asynchronous


message, it doesn’t wait for an answer before it proceeds.

Notation

Return message: The value returned from an object.

Notation

Self Call: A message that an object sends to itself, by sending


the message arrow back to the same lifeline.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 102
Actions

Call - An operation invoked on the object.

Return - A value is returned to the caller object.

Send - A signal is transmitted to an object.

Create - An instance of a class is created.

Destroy - An already created instance is destroyed.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 103
<<create>>

An object may create another object via a <<create>>


message.

Preferred
:A

<<create>>
:B

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 104
<<destroy>>

An object may destroy another object via a <<destroy>>


message.

Avoid modelling object destruction unless memory


management is critical.

:A :B

<<destroy>>

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 105
The Full Picture

X-Axis (objects)

object:
:AnotherClass :AClass
SomeClass

AnotherMethod() Object
Life Line
Y-Axis (time)

method

aMethod()
Activation
YetAnotherMethod box
Self call
return
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 106
Example

In the MVC architecture the following would be the


scenario to login.

LoginUI LoginController User

User Name

fetchUser : User
Password
validateUser

compareUser
Submit :boolean

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 107
Example

:LoginUI :LoginController
Customer
Username,pwd validateUser(u,p)
<<create>>
:User
fetctUser(u)

compareUser
(u,p,User)

User-status
User-status <<destroy>>
X

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 108
Try this out…..

ClientUI PinVerifier AccountManager

Pin Number
verifyPIn(pin ,acc)
getPin(acc) : actlPin
Account #
comparePin
(pin,actlpin) : boolean
Submit

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 109
Sample Scenario

Add Student Details

Use Screen Design as reference and identify MVC


structure.

AddStudentUI
StudentController
Student

How to draw the Sequence Diagram for the above scenario?

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 110
Sample Scenario

:AddStudent :Student
UserIinterface Controller
add(id,details) <<create>> :Student
add(id,details)
validate( id)
Invalid status
alt Invalid status
update(details)
Updated status
status

<<destroy>>

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 111
State Transition Diagram

A state chart diagram shows the sequence of states that an object


goes through during its lifetime, in response to outside stimuli
and messages.

It consists of states, both simple and composite events, actions


and transitions.

Generally used to model behaviour of individual objects.

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 112
State chart Diagram – An ATM Example

[Auth–good] Processing

Authentication Inputs given


[valid I/p]

[invalid I/p]
[Insert card]
Dispensing
Idle [Auth–failed]

Notifying

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 113
Order-Example

start
get first item
/

[Not all items checked] [All items checked &

Checking all items available] Dispatching


/get next item
do/check do/initiate
item delivery

e]
bl
va ed
ila
s a iv
activity

m ece
Delivered

ite R
[a Item
ll
Item Received
transition
[some items not in stock]

Waiting Delivered

self-transition state

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 114
stop
History State – Example

Washing Machine Example

Idle
Washing

H Soaking Composite state

Washing
[ Washing completed ] Sequential sub state
Rinsing

Drying

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 115
In Summary…
Modelling

UML, Magic Draw

OO Analysis, Noun Phrase Approach, CRC cards

Requirement Analysis

Use case Diagram / Specification

Class Diagram

Sequence Diagrams, State Transition Diagrams

Working with magic Draw UML

Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 116

You might also like