57
SIM3301 Object-Oriented Analysis 1 CHAPTER 6 OBJECT ORIENTED ANALYSIS

SIM3301Object-Oriented Analysis1 CHAPTER 6 OBJECT ORIENTED ANALYSIS

  • View
    235

  • Download
    0

Embed Size (px)

Citation preview

SIM3301 Object-Oriented Analysis 1

CHAPTER 6

OBJECT ORIENTED ANALYSIS

SIM3301 Object-Oriented Analysis 2

Learning Objectives

• Understand object oriented concepts• Be able to understand and/or draw object

oriented analysis modeling:– Use case diagram– Activity diagram– Class diagram– Sequence diagram– Collaboration diagram– State diagram

SIM3301 Object-Oriented Analysis 3

Object-Oriented Concepts

• Must be understood to apply class-based elements of the analysis model

• Key concepts:– Classes and objects– Attributes and operations– Encapsulation and instantiation– Inheritance

SIM3301 Object-Oriented Analysis 4

Classes• object-oriented thinking begins with

the definition of a class, often defined as:– template– generalized description– “blueprint” ... describing a collection of

similar items

• a superclass establishes a hierarchy of classes

• once a class of items is defined, a specific instance of the class can be identified

SIM3301 Object-Oriented Analysis 5

Building a Classclass name

attributes:

operations:

attributes:

operations

Class name

Attributes

Operations

SIM3301 Object-Oriented Analysis 6

Encapsulation/HidingClass encapsulates

both data and the logicalprocedures required tomanipulate the data

Achieves “information hiding”

method # 1

data

method # 2

method # 4

method # 5

method # 6

method # 3

Reduces the propagation of side effects when changes occur

SIM3301 Object-Oriented Analysis 7

Class Hierarchy

ChairTable Desk ”Chable"

instances of Chair

PieceOfFurniture (superclass)

subclasses of theSubclasses of the

furniture superclass

Instances of chair

Subclass inherit both

attributes and operations

from a superclass

SIM3301 Object-Oriented Analysis 8

Methods(a.k.a. Operations,

Services)An executable procedure that is encapsulated in a class and is designed to operate on one or more data attributes that are defined as part of the class.

A method is invoked via message passing.

SIM3301 Object-Oriented Analysis 9

Attributes

A collection of data values that describe a class

SIM3301 Object-Oriented Analysis 10

Objects

• Instances of a specific class

• Inherit a class attributes and operations

Class : STUDENT Object instance (object): Aliattributes : name, date of birth, etc.operations :calc_age, calc_cgpa, etc.

SIM3301 Object-Oriented Analysis 11

STUDENT

NameDOBAddressPhone

Calculate_ageCalculate_gpaRegister_course

Example

SIM3301 Object-Oriented Analysis 12

Object Oriented Analysis (OOA)

Based on objects rather than data or processes

The intent of OOA is to define all classes (and the relationships and behavior with them) that are relevant to the problem to be solved

• There are various OOA methods. Booch Method, Jacobson Method and Rumbaugh Method have collaborated into.

Unified Approach – Unified Modeling Language (UML)

SIM3301 Object-Oriented Analysis 13

THE OOA PROCESS THE OOA PROCESS

Use Case Modeling – shows functions

Class-based Modeling – Class diagram, CRC

Behavioral Model – State Diagram, Sequence

Diagram

SIM3301 Object-Oriented Analysis 14

USE CASE MODELINGUSE CASE MODELING

Illustrates the manner in which an actor interacts with the

system

ActorActor = “ Anything that communicates with the

system and that is external to the system”

Can be people or devices

Represent the roles that people/devices play as the system

operates

•Use CaseUse Case

Depiction of a system’s behavior or functionality under various conditions as the system responds to requests from users

Full functioning for a specific business purpose

Represent actor

Represent a use case

SIM3301 Object-Oriented Analysis 15

Use-Cases• A collection of user scenarios that describe the thread of usage of a system• Each scenario is described from the point-of-view of an “actor”• Each scenario answers the following questions: (eg: refer handout “Use

Case Template for Surveillance”)– Who is the primary actor, the secondary actor (s)?– What are the actor’s goals?– What preconditions should exist before the story begins?– What main tasks or functions are performed by the actor?– What extensions might be considered as the story is described?– What variations in the actor’s interaction are possible?– What system information will the actor acquire, produce, or change?– Will the actor have to inform the system about changes in the external

environment?– What information does the actor desire from the system?– Does the actor wish to be informed about unexpected changes?

SIM3301 Object-Oriented Analysis 16

Use-Case Diagram

homeowner

Access camera surveillance via the

Internet

Configure SafeHome system parameters

Set alarm

cameras

SafeHome

SIM3301 Object-Oriented Analysis 17

Withdraw Cash

Check Balance

Create Online Transaction

Bank ATM Machine

Eg: consider the interactions between a Bank Customer and an ATM

Bank Customer

SIM3301 Object-Oriented Analysis 18

Writing Use-Cases (Scenario)• Use case:Access camera surveillance-display camera views

(ACS-DCV)• Actor:homeowner

If I’m at remote location, I can use any PC with appropriate browser software to log on to the SafeHome Products Web site. I enter my user ID and two levels of passwords and, once I’m validated, I have access to all functionality for my installed SafeHome system. To access specific camera view, I select “surveillance” from the major function buttons displayed, I then select “pick camera”, and the floor plan of the house is displayed. I then select the camera that I’m interested in. Alternatively, I can look at thumbnail snapshots from all cameras simultaneously by selecting “all cameras” as my viewing choice. Once I choose a camera, I select “view” and a one-frame-per-second view appears in a viewing window that is identified by the camera ID. If I want to switch cameras, I select “pick a camera” and the original viewing window disappears and the floor plan of the house is displayed again. I then select the camera that I’m interested in. A new viewing window appears.

• A variation of this narrative use case is an ordered sequence of user actions – refer handout “Use Case Template for Surveillance “(Pressman, R. (2005). Software Engineering : A Practitioner's Approach, 6th edition. New York : McGraw-Hill)

• .

SIM3301 Object-Oriented Analysis 19

Use-Case Modeling• Relationships Between Use Cases

– Use cases may participate in relationships with other use-cases

– Two types• Extends

– Adds new behaviors or actions to a use case

• Include– One use case references another use case

20.1920.19

SIM3301 Object-Oriented Analysis 20

Example: Use-case diagram for a university registration system

(Correction: arrow direction should be in opposite direction)

20.2020.20

SIM3301 Object-Oriented Analysis 21

SIM3301 Object-Oriented Analysis 22

Activity DiagramActivity Diagram

Supplements the use-case by providing a diagrammatic representation of procedural flow

May adds additional detail not directly mentioned by the use case

Activity/Function Flow/Transition Decision

SIM3301 Object-Oriented Analysis 23

enter password and user ID

select major function

valid passwords/ ID

prompt for reentry

invalid passwords/ ID

input tries remain

no inputtries remain

select surveillance

other functions may also be

selected

thumbnail views select a specif ic camera

select camera icon

prompt for another view

select specific camera - thumbnails

exit this function see another camera

view camera output in labelled window An activity diagram for

Access Camera surveillance

SIM3301 Object-Oriented Analysis 24

Masuk kad Baca kad

Minta PINMasuk PIN

Sahkan PIN Adakah sah?

Pilih servis

[Tidak]

[Ya]

ATM Authorization

SIM3301 Object-Oriented Analysis 25

Class-Based Modeling

• Identify analysis classes by examining the problem statement

• Use a “grammatical parse” to isolate potential classes

• Identify the attributes of each class

• Identify operations that manipulate the attributes

SIM3301 Object-Oriented Analysis 26

Analysis Classes• External entities (e.g., other systems, devices, people) that produce or

consume information to be used by a computer-based system.• Things (e.g, reports, displays, letters, signals) that are part of the

information domain for the problem.• Occurrences or events (e.g., a property transfer or the completion of a

series of robot movements) that occur within the context of system operation.

• Roles (e.g., manager, engineer, salesperson) played by people who interact with the system.

• Organizational units (e.g., division, group, team) that are relevant to an application.

• Places (e.g., manufacturing floor or loading dock) that establish the context of the problem and the overall function of the system.

• Structures (e.g., sensors, four-wheeled vehicles, or computers) that define a class of objects or related classes of objects.

SIM3301 Object-Oriented Analysis 27

Selecting Classes—Criteria

• Retained Information

• Needed services – have a set of identifiable operations

• Multiple attributes

• Common attributes

• Common operations

• Essential requirements

SIM3301 Object-Oriented Analysis 28

CRC Modeling

• Analysis classes have “responsibilities”– Responsibilities are the attributes and operations

encapsulated by the class

• Analysis classes collaborate with one another– Collaborators are those classes that are required to

provide a class with the information needed to complete a responsibility.

– In general, a collaboration implies either a request for information or a request for some action.

SIM3301 Object-Oriented Analysis 29

CRC Modeling

Class:

Description:

Responsibility: Collaborator:

Class:

Description:

Responsibility: Collaborator:

Class:

Description:

Responsibility: Collaborator:

Class: FloorPlan

Description:

Responsibility: Collaborator:

incorporates walls, doors and windows

shows position of video cameras

defines floor plan name/type

manages floor plan positioning

scales floor plan for display

Wall

Camera

SIM3301 Object-Oriented Analysis 30

Class Types• Entity classes, also called model or business classes, are

extracted directly from the statement of the problem (e.g., FloorPlan and Sensor).

• Boundary classes are used to create the interface (e.g., interactive screen or printed reports) that the user sees and interacts with as the software is used.

• Controller classes manage a “unit of work” [UML03] from start to finish. That is, controller classes can be designed to manage – the creation or update of entity objects; – the instantiation of boundary objects as they obtain information from

entity objects; – complex communication between sets of objects; – validation of data communicated between objects or between the user

and the application.

SIM3301 Object-Oriented Analysis 31

Responsibilities• System intelligence should be distributed across

classes to best address the needs of the problem• Each responsibility should be stated as generally

as possible• Information and the behavior related to it should

reside within the same class• Information about one thing should be localized

with a single class, not distributed across multiple classes.

• Responsibilities should be shared among related classes, when appropriate.

SIM3301 Object-Oriented Analysis 32

Collaborations

• Classes fulfill their responsibilities in one of two ways:– A class can use its own operations to manipulate its own

attributes, thereby fulfilling a particular responsibility, or – a class can collaborate with other classes.

• Collaborations identify relationships between classes• Collaborations are identified by determining whether a

class can fulfill each responsibility itself• three different generic relationships between classes

[WIR90]: – the is-part-of relationship– the has-knowledge-of relationship– the depends-upon relationship

SIM3301 Object-Oriented Analysis 33

Composite Aggregate Class

Player

PlayerHead PlayerArms PlayerLegsPlayerBody

SIM3301 Object-Oriented Analysis 34

Associations

• Two analysis classes are often related to one another in some fashion– In UML these relationships are called

associations– Associations can be refined by indicating

multiplicity (the term cardinality is used in data modeling

SIM3301 Object-Oriented Analysis 35

Multiplicity

WallSegment Window Door

Wall

is used to buildis used to build

is used to build1..*

1 1 1

0..* 0..*

SIM3301 Object-Oriented Analysis 36

Behavioral Modeling

• The behavioral model indicates how software will respond to external events or stimuli. To create the model, the analyst must perform the following steps:

• Evaluate all use-cases to fully understand the sequence of interaction within the system.

• Identify events that drive the interaction sequence and understand how these events relate to specific objects.

• Create a sequence for each use-case.• Build a state diagram for the system.• Review the behavioral model to verify accuracy and

consistency.

SIM3301 Object-Oriented Analysis 37

State Representations• In the context of behavioral modeling, two

different characterizations of states must be considered: – the state of each class as the system

performs its function and– the state of the system as observed from the

outside as the system performs its function

SIM3301 Object-Oriented Analysis 38

The States of a System• state—a set of observable circum-

stances that characterizes the behavior of a system at a given time

• state transition—the movement from one state to another

• event—an occurrence that causes the system to exhibit some predictable form of behavior

• action—process that occurs as a consequence of making a transition

SIM3301 Object-Oriented Analysis 39

Behavioral Modeling• make a list of the different states of a

system (How does the system behave?)

• indicate how the system makes a transition from one state to another (How does the system change state?)– indicate event– indicate action

• draw a state diagram or a interaction diagram (sequence diagram or collaboration diagram)

SIM3301 Object-Oriented Analysis 40

Sequence diagramSequence diagram

A representation of how events cause flow from one object to another as a function of time.

Events are identified by examining a use case

Is a shorthand version of a use case

Sequence diagram consists of:• Objects • Lifeline• Messages/Event

objects

lifeline

(time)

message/event

SIM3301 Object-Oriented Analysis 41

Sequence Diagram

prepare()

Message/event

needsToReorder() Self Delegation

anOrder Object

Object and Class

anOrder: Order

SIM3301 Object-Oriented Analysis 42

messageA( )

messageB(string)

messageC( )

Object A:Class A

: Actor

Object B:Class B

lifeline

object

message

activation(optional)

SIM3301 Object-Oriented Analysis 43

Identifying events with the Use-Case

• Use case for a small portion of the SafeHome security function

The homeowner uses the keypad to key in a four-digit

password. The password is compared with the valid

password stored in the system. If the password is

incorrect, the control panel will beep once and reset

itself for additional input. If the password is correct, the

control panel awaits further action.

SIM3301 Object-Oriented Analysis 44

Sequence Diagramhomeowner control panel sensorssystem sensors

system ready

reading

request lookupcomparing

result

password entered

password = correctrequest activation

activation successful

lockednumberOfTries > maxTries

selecting

timer > lockedTimeA

A

Figure 8.27 Sequence diagram (partial) for SafeHome security function

activation successful

SIM3301 Object-Oriented Analysis 45

STAFF

printRecordcalculateSalary

CLOCKSTAFF

printRecordcalculateSalary

COMISSIONSTAFF

printRecordcalculateSalary

printRecord( )

Bob:ClockStaff

Ali : User

calculateSalary( )

Class diagram Sequence diagram

Bob:ClockStaff

Ali : User

SIM3301 Object-Oriented Analysis 46

DeliveryItem

itemnumberquantity

etc…

ReOrderItem

itemnumberquantity

etc…

Order

orderNumberdate

etc…

prepare()

OrderLine

itemnumberquantity

etc…

prepare()

StockItem

orderNumberminQuantity

dateetc…

check():booleanremove()

needsToReorder(): boolean

is_for

new()

new()

OrderEntryWindow

choose()

SIM3301 Object-Oriented Analysis 47

prepare() * prepare()check()

[check=“true”] remove()

needsToReorder()

[needsToReorder=“true”]

new

AReorder Item

aDelivery Item

anOrder Entry window

anOrder anOrder Line

aStock Item

[check=“true”] new

choose()

SIM3301 Object-Oriented Analysis 48

Computer

print(filename)

PrintServer

status(): integer

print(file)

Printer

print(file)

Queue

store(file)

uses

Managed by

SIM3301 Object-Oriented Analysis 49

aComputer: Computer

aPrintServer:PrintServer

aPrinter:Printer

print(file)

aUser: User

print(filename)

aQueue:Queue

[printer free] print(file)

[printer busy] store(file)

SIM3301 Object-Oriented Analysis 50

Collaboration DiagramCollaboration Diagram Shows the relationships among objects

Consists of: Objects Lines connecting the objects Messages

Object A

Object B

ObjectC

1. message1

2. Message23. Message3

SIM3301 Object-Oriented Analysis 51

CourseForm

AcademicStaff

StudentSchedule

: Student

keyInCourseInfo

addCourse

newCourse

CourseForm

AcademicStaff

StudentSchedule

Student

1. keyInCourseInfo

2. addCourse

3. newCourse

Interaction diagrams

SIM3301 Object-Oriented Analysis 52

State DiagramState Diagram Indicates how an individual class changes state based on

external events Represents states for each class and the events (triggers) that

cause changes between these states One state diagram for each class. Event – causes the transition, the labels for each arrow Action – occurs concurrently with the state transition or as a

consequence of it. Generally involves one or more operations (responsibilities)

Transition – represented by an arrow Guard condition– a boolean condition that must be satisfied in

order for the transition to occur Activity - represents a long-running task during that state. Actions vs activity

Actions cannot be interrupted, activity can be interrupted by an incoming event. 

Both represent an operation on the object being studied.  For example, an operation that sets an attribute would be considered an

action, while a long calculation might be an activity. 

SIM3301 Object-Oriented Analysis 53

State-Diagram NotationState-Diagram Notation

State 2 . . .

event [condition] /action

Event which causes the transition

Occurs concurrently with the state transition

Condition that must be satisfied in order for the transition to occur

End state

State 1do/activity 1

Initial state

An operation that is perform when an object is in a certain state

SIM3301 Object-Oriented Analysis 54

Example : State Diagram State Diagram

PaidPayingUnpaid

Invoice createdInvoice destroyed

SIM3301 Object-Oriented Analysis 55

InitializationInitialization

OpenOpen ClosedClosed

add student/numStudent=0

add student [numStudent<50]

cancel

cancel

delete

Class: CourseSchedule

bina jadual kursus

dibuka pd pelajar

ditutup – kuota penuh

Dibatalkan atau tidak ditawarkan lagi

addstudent [numStudent=50]

Cancelled

do:Send cancellation notices

SIM3301 Object-Oriented Analysis 56

State Diagram for the ControlPanel Class

reading

locked

selecting

password entered

comparing

password = incorrect & numberOfTries < maxTries

password = correct

activation successful

key hit

do: validatePassword

numberOfTries > maxTries

timer < lockedTime

timer > lockedTime

SIM3301 Object-Oriented Analysis 57

State Diagram

Figure 7.6 Preliminary UML state diagram for a photocopier

Initialization

system status=“not ready” display msg = “please wait” display status = blinking

entry/ switch machine on do: run diagnostics do: initiate all subsystems

turn copier “on“

subsystems ready system status=“Ready”

display msg = “enter cmd” display status = steady

entry/ subsystems ready do: poll user input panel do: read user input do: interpret user input

Readingcommands

system status=“Copying” display msg= “copy count =” display message=#copies display status= steady

entry/ start copies do: manage copying do: monitor paper tray do: monitor paper flow

Making copies

start copies

system status=“Jammed” display msg= “paper jam” display message=location display status= blinking

entry/ paper jammed do: determine location do: provide corrective msg. do: interrupt making copies

problem diagnosis

paper jammed

system status=“load paper” display msg= “load paper” display status= blinking

entry/ paper empty do: lower paper tray do: monitor fill switch do: raise paper tray

load paper

paper tray empty

not jammed

paper full

turn copier “off”

not jammed

copies complete