Object Oriented Analysis and Design

23
Object Oriented Analysis and Design Chapter 4: Analysis

description

Object Oriented Analysis and Design. Chapter 4: Analysis. Welcome!. 10 (+) week book study Tom Perkins [email protected] Books available at Nerdbooks.com http://69.41.237.216/STUDYGROUPSIG/OOAD. Welcome!. Chapter 4: Analysis [email protected]. Objectives. Review Homework - PowerPoint PPT Presentation

Transcript of Object Oriented Analysis and Design

Page 1: Object Oriented Analysis and Design

Object Oriented Analysis and DesignChapter 4: Analysis

Page 2: Object Oriented Analysis and Design

Welcome!

• 10 (+) week book study

• Tom Perkins– [email protected]

m

• Books available at Nerdbooks.com

• http://69.41.237.216/STUDYGROUPSIG/OOAD

Page 3: Object Oriented Analysis and Design

Welcome!

• Chapter 4: Analysis• [email protected]

Page 4: Object Oriented Analysis and Design

Objectives• Review Homework• Review Doug’s Dog Door app• Review existing Class Diagrams• Introduce new problem design opportunity• Modified Use Case• 2 ways to handle (Randy and Sam)• Delegation• Textual Analysis• Associations• In-class exercise• Homework assignment• Summary

Page 5: Object Oriented Analysis and Design

Homework Review

• Handouts• Use Cases:

– Single goal,Single Start, Single End– Happy Path, Alternative Paths– Used to communicate with customers– Part of Agile design/development process

• Problem: Write a Use Case describing how an ATM handles a cash withdrawal transaction

• Walkthru Use Case

Page 6: Object Oriented Analysis and Design

Your new programming job:

Doug’s Dog Doors

(High tech, automated dog doors)

Todd GinaFido

Your first CustomersWhat they want:

An automated, remote-

controlled

Dog Door barks !!!

want to push button to open door

No Problem

!!!

Page 7: Object Oriented Analysis and Design

Todd and Gina’s Dog Door, Version 2.0 (Review)

Dog Door Use Case

1. Fido barks to be let out.

2. Todd or Gina hears Fido barking.

3. Todd or Gina presses the button on the remote control.

4. The dog door opens.

5. Fido goes outside.

6. Fido does his business..

6.1 The door shuts automatically.

6.2 Fido barks to be let in.

6.3 Todd or Gina hears Fido barking (again).

6.4 Todd or Gina presses button on remote control.

6.5 The dog door opens (again).

7. Fido goes back inside.

8. The door shuts automatically.

Page 8: Object Oriented Analysis and Design

Doug and Gina’s Idea

It (the dog door) is working great, but what if …

Fido

barks (Woof-Woof )!!!

Bark Recognizer Attachment

Dog Door Opens!

Page 9: Object Oriented Analysis and Design

A Revised Use Case

Main Path

1. Fido barks to be let out

2. Bark Recognizer hears

3. Bark Recognizer send open request

4. Dog door opens

5. Fido goes outside

6. Fido does his business.

7. Fido goes back inside.

8. Dog door shuts automatically

Alternate paths:

2.1 Todd or Gina hears Fido

3.1 Todd or Gina presses remote control

6.1 Dog door shuts automatically

6.2 Fido barks

6.3 Bark recognizer hears bark

6.3.1 Todd or Gina hears

6.4. Bark recognizer requests

6.4.1 Todd or Gina presses remote

6.5 Dog door opens

Page 10: Object Oriented Analysis and Design

dogDoor

open:bool

Open()

Close()

isOpen():bool

remote

door:dogDoor

pressButton()

recognizer

door:dogDoor

recognize(String)

Our Classes

Page 11: Object Oriented Analysis and Design

A new problem …

Bruce

Bruce’s owner: “Don’t get me wrong, I like the dog door. The problem is that it opens when other dogs in the neighborhood bark. Can you do something to fix this?”

Page 12: Object Oriented Analysis and Design

A modified Use Case2. The bark recognizer “hears” a bark.

3. If it’s the owner’s dog barking, the bark recognizer sends a request to the door to open.

6.3 The bark recognizer “hears” a bark.

6.4 If it’s the owner’s dog barking, the bark recognizer sends a request to the door to open.

Page 13: Object Oriented Analysis and Design

Randy’s solution public class DogDoor { private boolean open; private string allowedBark;

public DogDoor() { open = false; } public void setAllowedBark(String bark) {

this.allowedBark = bark; } public string getAllowedBark() { return allowedBark; } // other code}

dogDoor

open:bool allowedBark:String

Open()Close()isOpen():bool setAllowedBark(string)

getAllowedBark(string)

Page 14: Object Oriented Analysis and Design

public class Bark { private string sound; public Bark(string sound){ this.sound = sound; } public string getSound() { return sound; } public boolean equals(Object bark){ if (bark instanceof Bark) { Bark otherBark = (Bark) bark; if (this.sound.equalsIgnoreCase(bark.getSound() { return true; } } return false;}

Sam (Mr Object Guy)’s Solution Bark

sound:string

getSound:string equals(Object bark): boolean

Page 15: Object Oriented Analysis and Design

Comparing “recognize()” methods

public class BarkRecognizer(){ public void recognize(string bark) . . . if (door.getAllowedBark().equals(bark){ door.open();} else {print(“no,no,no!”)

public class BarkRecognizer(){ public void recognize(Bark bark) print(“Heard “ + bark.getSound()) if (door.getAllowedBark().equals(bark){ door.open();} else {print(“no,no,no!”)

String comparison Randy

Delegated comparison-Sam

Page 16: Object Oriented Analysis and Design

Take-away

• Loosely-coupled classes: It’s a good thing!• Suppose instead of a string, we have

a .WAV file to record Bruce’s voice.• Randy must change both the DogDoor and

Recognizer classes; Sam has to change only the Recognizer class.

• Delegation shields your objects from implementation changes to other objects in your application.

Page 17: Object Oriented Analysis and Design

… but Maria wins the laptop computer

• She allowed many variations of Bruce’s bark

• allowedBarks:Bark[*]– Multiplicity of an attribute (how many

times it occurs)

Page 18: Object Oriented Analysis and Design

What’s Maria’s approach?

• Textual analysis• Examine the Use Case for Nouns

(possible classes) and Verbs (possible methods)

Page 19: Object Oriented Analysis and Design

Our Use Case Find the nouns and verbs

Main Path

1. Fido barks to be let out

2. Bark Recognizer hears

3. If it’s the owner’s dog barking, the bark recognizer sends a request to the door to open.

4. Dog door opens

5. Fido goes outside

6. Fido does his business.

7. Fido goes back inside.

8. Dog door shuts automatically

Alternate paths:

2.1 Todd or Gina hears Fido

3.1 Todd or Gina presses remote control

6.1 Dog door shuts automatically

6.2 Fido barks

6.3 Bark recognizer hears bark

6.3.1 Todd or Gina hears

6.4. If it’s the owner’s dog barking, the bark recognizer sends a request to the door to open.

6.4.1 Todd or Gina presses remote

6.5 Dog door opens

Page 20: Object Oriented Analysis and Design

Bark

sound:string

getSound:string equals(Object bark): boolean

remote

door:dogDoor

pressButton()

recognizer

door:dogDoor

recognize(String)

dogDoor

open:bool allowedBark:String

Open()Close()isOpen():bool setAllowedBark(string)

getAllowedBark(string)

door

allowedBarks

door 11

*

Associations (has-a)

Page 21: Object Oriented Analysis and Design

Exercise

• Divide into groups of 3 or 4• Using the Homework Use Case

Handout– Identify the nouns– Identify the verbs

• What are some candidate classes?• What are some candidate methods?

Page 22: Object Oriented Analysis and Design

Homework

• Use the classes you derived from the ATM Withdrawal Use Case(s)

• Construct a class diagram for these classes.

Page 23: Object Oriented Analysis and Design

Finis