Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Analysis and Design Chapter 4: Analysis.

Similar presentations


Presentation on theme: "Object Oriented Analysis and Design Chapter 4: Analysis."— Presentation transcript:

1 Object Oriented Analysis and Design Chapter 4: Analysis

2 Welcome! 10 (+) week book study Tom Perkins –tomperki@gmail.comtomperki@gmail.com Books available at Nerdbooks.com http://69.41.237.216 /STUDYGROUPSIG/ OOADhttp://69.41.237.216 /STUDYGROUPSIG/ OOAD

3 Welcome! Chapter 4: Analysis tomperki@gmail.com

4 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

5 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

6 Your new programming job: Doug’s Dog Doors (High tech, automated dog doors) Todd Gina Fido Your first Customers What they want: An automated, remote- controlled Dog Door barks !!! want to push button to open door No Problem !!!

7 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.

8 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!

9 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

10 dogDoor open:bool Open() Close() isOpen():bool remote door:dogDoor pressButton() recognizer door:dogDoor recognize(String) Our Classes

11 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?”

12 A modified Use Case 2. 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. …

13 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)

14 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

15 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

16 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.

17 … 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)

18 What’s Maria’s approach? Textual analysis Examine the Use Case for Nouns (possible classes) and Verbs (possible methods)

19 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

20 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 1 1 * Associations (has-a)

21 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?

22 Homework Use the classes you derived from the ATM Withdrawal Use Case(s) Construct a class diagram for these classes.

23 Finis


Download ppt "Object Oriented Analysis and Design Chapter 4: Analysis."

Similar presentations


Ads by Google