Post on 31-Dec-2015
transcript
Welcome!
• 10 (+) week book study
• Tom Perkins– tomperki@gmail.co
m
• Books available at Nerdbooks.com
• http://69.41.237.216/STUDYGROUPSIG/OOAD
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
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
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
!!!
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.
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!
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
dogDoor
open:bool
Open()
Close()
isOpen():bool
remote
door:dogDoor
pressButton()
recognizer
door:dogDoor
recognize(String)
Our Classes
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?”
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.
…
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)
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
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
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.
… 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)
What’s Maria’s approach?
• Textual analysis• Examine the Use Case for Nouns
(possible classes) and Verbs (possible methods)
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
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)
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?
Homework
• Use the classes you derived from the ATM Withdrawal Use Case(s)
• Construct a class diagram for these classes.