lecture 14 & 15: object- oriented analysis anita s. malik [email protected] adapted from...

37
CS540 Software Desi gn 2 Lecture 14 & 15 Object-Oriented Paradigm Object-Oriented Paradigm Object-oriented paradigm Object-oriented paradigm Reaction to perceived shortcomings Reaction to perceived shortcomings in structured paradigm in structured paradigm Problem of larger products Problem of larger products Data and action treated as equal Data and action treated as equal partners partners

Upload: joshua-moody

Post on 01-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 2Lecture 14 & 15

Object-Oriented ParadigmObject-Oriented Paradigm

Object-oriented paradigmObject-oriented paradigm Reaction to perceived shortcomings in Reaction to perceived shortcomings in

structured paradigmstructured paradigm Problem of larger productsProblem of larger products Data and action treated as equal Data and action treated as equal

partnerspartners

Page 2: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 3Lecture 14 & 15

Object-Oriented Paradigm Object-Oriented Paradigm (contd)(contd)

Object consists ofObject consists of Data (attributes, state variables, Data (attributes, state variables,

instance variables, fields, data instance variables, fields, data members), andmembers), and

Actions (methods, member functions)Actions (methods, member functions) Objects are independent unitsObjects are independent units

Conceptual independenceConceptual independence Physical independencePhysical independence

Page 3: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 4Lecture 14 & 15

Object-Oriented Analysis Object-Oriented Analysis (OOA)(OOA)

Semi-formal specification technique Semi-formal specification technique Multiplicity of different methods Multiplicity of different methods

BoochBooch OMTOMT ObjectoryObjectory Shlaer-MellorShlaer-Mellor Coad-YourdonCoad-Yourdon

All essentially equivalentAll essentially equivalent Nowadays, we represent OOA using Nowadays, we represent OOA using

UML (unified modeling language)UML (unified modeling language)

Page 4: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 5Lecture 14 & 15

The Three Steps of OOAThe Three Steps of OOA 1.1. Use-case modelingUse-case modeling

Determine how the various results are computed Determine how the various results are computed by the product (without regard to sequencing)by the product (without regard to sequencing)

Largely action orientedLargely action oriented 2.2. Class modeling (“object modeling”)Class modeling (“object modeling”)

Determine the classes and their attributesDetermine the classes and their attributes Purely data-orientedPurely data-oriented

3.3. Dynamic modeling Dynamic modeling Determine the actions performed by or to each Determine the actions performed by or to each

classclass Purely action-orientedPurely action-oriented

Iterative processIterative process

Page 5: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 6Lecture 14 & 15

Elevator Problem: OOAElevator Problem: OOA 1. 1. Use-Case ModelingUse-Case Modeling

Use case: Generic description of overall Use case: Generic description of overall functionalityfunctionality

Get comprehensive insight into behavior of Get comprehensive insight into behavior of productproduct

Page 6: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 7Lecture 14 & 15

Normal ScenarioNormal Scenario

Page 7: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 8Lecture 14 & 15

Exception ScenarioException Scenario

Page 8: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 9Lecture 14 & 15

Use CaseUse Case

Use Case NameUse Case Name ActorsActors Pre-ConditionsPre-Conditions Normal FlowNormal Flow Post-ConditionsPost-Conditions Exceptions or Alternate FlowsExceptions or Alternate Flows

Page 9: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 10Lecture 14 & 15

Class ModelingClass Modeling

Extract classes and their attributesExtract classes and their attributes Represent them using an entity-Represent them using an entity-

relationship diagramrelationship diagram Deduce the classes from use cases Deduce the classes from use cases

and their scenariosand their scenarios Often there are many scenariosOften there are many scenarios

Possible danger: too many candidate Possible danger: too many candidate classesclasses

Page 10: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 11Lecture 14 & 15

Two Approaches to Class Two Approaches to Class ModelingModeling

Noun extractionNoun extraction Always worksAlways works

CRC classesCRC classes Need to have domain Need to have domain

expertiseexpertise

Page 11: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 12Lecture 14 & 15

Noun ExtractionNoun Extraction

Stage 1. Concise Problem DefinitionStage 1. Concise Problem Definition Define product in single sentence Define product in single sentence

Buttons in elevators and on the floors control Buttons in elevators and on the floors control the motion of n elevators in a building with m the motion of n elevators in a building with m floors.floors.

Page 12: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 13Lecture 14 & 15

Noun Extraction (contd)Noun Extraction (contd)

Stage 2. Informal StrategyStage 2. Informal Strategy Incorporate constraints, express result Incorporate constraints, express result

in a single paragraph in a single paragraph Buttons in elevators and on the floors control Buttons in elevators and on the floors control

movement of n elevators in a building with m movement of n elevators in a building with m floors. Buttons illuminate when pressed to floors. Buttons illuminate when pressed to request the elevator to stop at a specific floor; request the elevator to stop at a specific floor; illumination is canceled when the request has illumination is canceled when the request has been satisfied. When an elevator has no been satisfied. When an elevator has no requests, it remains at its current floor with its requests, it remains at its current floor with its doors closed.doors closed.

Page 13: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 14Lecture 14 & 15

Noun Extraction (contd)Noun Extraction (contd) Stage 3. Formalize the StrategyStage 3. Formalize the Strategy

Identify nouns in informal strategy. Use nouns Identify nouns in informal strategy. Use nouns as candidate classes as candidate classes

NounsNouns button, elevator, floor, movement, building, button, elevator, floor, movement, building,

illumination, door illumination, door floorfloor, , buildingbuilding, , door are outside problem door are outside problem

boundary — excludeboundary — exclude movementmovement and illuminationand illumination are abstract nouns are abstract nouns

— exclude (may become attributes)— exclude (may become attributes) Candidate classes: Candidate classes: ElevatorElevator and and ButtonButton Subclasses: Subclasses: Elevator Button Elevator Button andand Floor Button Floor Button

Page 14: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 15Lecture 14 & 15

First Iteration of Class First Iteration of Class DiagramDiagram

ProblemProblem Buttons do not communicate directly with elevatorsButtons do not communicate directly with elevators We need an additional class:We need an additional class: Elevator ControllerElevator Controller

Page 15: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 16Lecture 14 & 15

Second Iteration of Class Second Iteration of Class DiagramDiagram

All relationships All relationships are now 1-to-n are now 1-to-n Makes design Makes design

and and implementation implementation easier easier

Page 16: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 17Lecture 14 & 15

CRC CardsCRC Cards Class Responsibility Collaboration (CRC)Class Responsibility Collaboration (CRC) Used since 1989 for OOAUsed since 1989 for OOA For each class, fill in card showingFor each class, fill in card showing

Name of Name of cclasslass Functionality (Functionality (rresponsibility)esponsibility) List of classes it invokes (List of classes it invokes (ccollaboration)ollaboration) Now automated (CASE tool component)Now automated (CASE tool component)

StrengthStrength When acted out by team members, powerful When acted out by team members, powerful

tool for highlighting missing or incorrect itemstool for highlighting missing or incorrect items WeaknessWeakness

Domain expertise is neededDomain expertise is needed

Page 17: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 18Lecture 14 & 15

3. Dynamic Modeling3. Dynamic Modeling

Produce UML state Produce UML state diagramdiagram

State, event, State, event, predicate predicate distributed over distributed over state diagramstate diagram

UML “guards” are UML “guards” are in bracketsin brackets

Page 18: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 19Lecture 14 & 15

Testing during the OOA Testing during the OOA PhasePhase

CRC cards are an excellent testing CRC cards are an excellent testing techniquetechnique

Page 19: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 20Lecture 14 & 15

CRC CardsCRC Cards Consider responsibilityConsider responsibility

1.1. Turn on elevator buttonTurn on elevator button

Totally unacceptable for object-Totally unacceptable for object-oriented paradigmoriented paradigm

Responsibility-driven design ignoredResponsibility-driven design ignored Information hiding ignoredInformation hiding ignored Responsibility Responsibility

1.1. Turn on elevator button Turn on elevator button

should beshould be1.1. Send message to Send message to Elevator ButtonElevator Button to to turn itself on turn itself on

Page 20: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 21Lecture 14 & 15

CRC Cards (contd)CRC Cards (contd)

A class has been overlookedA class has been overlooked Elevator doors have a Elevator doors have a statestate that that

changes during execution (class changes during execution (class characteristic)characteristic)

Add class Add class Elevator DoorsElevator Doors Safety considerationsSafety considerations

Reconsider class modelReconsider class model Then reconsider dynamic model, Then reconsider dynamic model,

use-case modeluse-case model

Page 21: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 22Lecture 14 & 15

Second Iteration of CRC Second Iteration of CRC CardCard

Page 22: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 23Lecture 14 & 15

Third Iteration of Class Third Iteration of Class DiagramDiagram

Page 23: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 24Lecture 14 & 15

Second Iteration of Normal Second Iteration of Normal ScenarioScenario

Page 24: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 25Lecture 14 & 15

Elevator Problem: OOA Elevator Problem: OOA (contd)(contd)

All three models are now fineAll three models are now fine We should rather say:We should rather say:

All three models are fine All three models are fine for nowfor now We may need to return to the We may need to return to the

object-oriented analysis phase object-oriented analysis phase during the object-oriented design during the object-oriented design phasephase

Page 25: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 26Lecture 14 & 15

Why Is All This Iteration Why Is All This Iteration Needed?Needed?

Perhaps the method is not yet mature?Perhaps the method is not yet mature? Waterfall model (explicit feedback loops)Waterfall model (explicit feedback loops) Rapid prototyping model (aim: to reduce Rapid prototyping model (aim: to reduce

iteration)iteration) Incremental model, andIncremental model, and Spiral model Spiral model

Latter two explicitly reflect iterative Latter two explicitly reflect iterative approachapproach

Iteration is an intrinsic property of all Iteration is an intrinsic property of all software productionsoftware production Especially for medium- and large-scale productsEspecially for medium- and large-scale products Expect iteration in the object-oriented paradigmExpect iteration in the object-oriented paradigm

Page 26: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 27Lecture 14 & 15

CASE tools for OOA phaseCASE tools for OOA phase

Diagrams play a major roleDiagrams play a major role Diagrams often changeDiagrams often change

Need a diagramming toolNeed a diagramming tool Many tools go furtherMany tools go further

All modern tools support All modern tools support UMLUML ExampleExample

RoseRose

Page 27: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 28Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: OOAOOA

Use-case model for making a reservationUse-case model for making a reservation

Page 28: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 29Lecture 14 & 15

Making a Reservation: Making a Reservation: Extended ScenarioExtended Scenario

Page 29: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 30Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: OOAOOA

Use-case for returning and scanning a Use-case for returning and scanning a postcardpostcard

Page 30: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 31Lecture 14 & 15

Postcards: Extended Postcards: Extended ScenarioScenario

Page 31: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 32Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: Class ModelingClass Modeling

Stage 1. Concise Problem Stage 1. Concise Problem DefinitionDefinition Define product in single sentence Define product in single sentence

A computerized system is needed to provide A computerized system is needed to provide information regarding the efficacy of a information regarding the efficacy of a special meals program.special meals program.

Page 32: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 33Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: Noun Extraction (contd)Noun Extraction (contd)

Stage 2. Informal StrategyStage 2. Informal Strategy Incorporate constraints, express result in Incorporate constraints, express result in

a single paragraph a single paragraph Reports are to be generated to document the efficacy Reports are to be generated to document the efficacy

of the special meals program. The reports concern of the special meals program. The reports concern meals loaded on flights, flights boarded by passengers, meals loaded on flights, flights boarded by passengers, names and addresses of passengers, meal quality, and names and addresses of passengers, meal quality, and low-sodium meals.low-sodium meals.

Page 33: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 34Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: Noun Extraction (contd)Noun Extraction (contd)

Stage 3. Formalize the StrategyStage 3. Formalize the Strategy Identify nouns in informal strategy. Use nouns as Identify nouns in informal strategy. Use nouns as

candidate classes candidate classes NounsNouns

report, efficacy, program, percentage, meal, flight, report, efficacy, program, percentage, meal, flight, boarding, passenger, name, address, qualityboarding, passenger, name, address, quality

efficacy, program, percentage, boarding, quality are efficacy, program, percentage, boarding, quality are abstract nouns — exclude (may become attributes)abstract nouns — exclude (may become attributes)

name, address are attributes of passengername, address are attributes of passenger Question: Should meal and flight be classes?Question: Should meal and flight be classes?

It is easier to add classes than to remove themIt is easier to add classes than to remove them Candidate classes: Candidate classes: ReportReport and and PassengerPassenger

Page 34: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 35Lecture 14 & 15

First Iteration of Class First Iteration of Class Diagram)Diagram)

Problems with this class diagramProblems with this class diagram Data for reports are needed on a per-flight basisData for reports are needed on a per-flight basis Each report has to access multiple flightsEach report has to access multiple flights Each flight has multiple passengersEach flight has multiple passengers Six reports (not four) are neededSix reports (not four) are needed

Page 35: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 36Lecture 14 & 15

Second Iteration of Class Second Iteration of Class Diagram (contd)Diagram (contd)

Cause of Cause of our our problemsproblems FlightFlight should should

have been a have been a candidate candidate classclass

BUT, we all BUT, we all have 20–20 have 20–20 hindsighthindsight

Page 36: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 37Lecture 14 & 15

Air Gourmet Case Study: Air Gourmet Case Study: Dynamic ModelDynamic Model State State

diagramdiagram

Page 37: Lecture 14 & 15: Object- Oriented Analysis Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

CS540 Software Design 38Lecture 14 & 15

Challenges of the OOA Challenges of the OOA PhasePhase

Do not class the boundary into Do not class the boundary into object-oriented designobject-oriented design

Do not allocate methods to classes Do not allocate methods to classes yetyet