Presentation is loading. Please wait.

Presentation is loading. Please wait.

HFOOAD Chapter 3 Change: the constant in software development.

Similar presentations


Presentation on theme: "HFOOAD Chapter 3 Change: the constant in software development."— Presentation transcript:

1 HFOOAD Chapter 3 Change: the constant in software development

2 2 And you’re responsible for changing your programs

3 Great dog door, but… 3 Can you add some hardware to recognize Fido’s bark when he wants go to out and come back in and automatically open the door? That way we don’t need to hear him or find that darn remote that keeps getting lost.

4 What might change? 4 Hardware (new and modified) The use case The code (implementation and tests) … 1 2 3 4

5 The old scenario 5 The dog door opens (again). 6.5 Fido barks to be let out. 1 Todd or Gina hears Fido barking. 2 Todd or Gina presses the button on the remote control. 3 The dog door opens. 4 Fido goes outside. 5 Fido does his business. 6 The door shuts automatically. 6.1 Fido barks to be let back inside. 6.2 Todd or Gina hears Fido barking (again). 6.3 Todd or Gina presses the button on the remote control. Fido goes back inside. 7 The door shuts automatically. 8 Woof! Gina, open the dog door…Fido won’t quit barking! I feel much better now! Woof! Again with the barking! Someone let Fido back inside 6.4

6 The new scenario 6 The dog door opens (again). 6.5 Fido barks to be let out. 1 Todd or Gina hears Fido barking. 2 Todd or Gina presses the button on the remote control. 3 The dog door opens. 4 Fido goes outside. 5 Fido does his business. 6 The door shuts automatically. 6.1 Fido barks to be let back inside. 6.2 Todd or Gina hears Fido barking (again). 6.3 Todd or Gina presses the button on the remote control. Fido goes back inside. 7 The door shuts automatically. 8 Woof! Gina, open the dog door…Fido won’t quit barking! I feel much better now! Woof! Again with the barking! Someone let Fido back inside 6.4 The bark recognizer “hears” a bark (again). 6.3.1 The bark recognizer sends a request to the door to open. 6.4.1 The bark recognizer “hears” a bark. 2.1 The bark recognizer sends a request to the door to open. 3.1

7 We now have an alternate path 7 Does this make sense to you? How would you improve it?

8 An improved document 8

9 A chain of development artifacts 9 Requirements Design documents and classes Code Tests Documentation

10 Review the old design 10 Association Multiplicity

11 Our new design 11

12 The new BarkRecognizer class 12 public class BarkRecognizer { private DogDoor door; public BarkRecognizer(DogDoor door) { this.door = door; } public void recognize(String bark) { System.out.println(" BarkRecognizer: Heard a '" + bark + "'"); door.open(); } This is really simple, trivial actually.

13 13 It’s really great that we applied the Information Expert. Why is it so great? Is there a principle here?

14 If we hadn’t refactored … 14 Just copy the code for closing the door automatically from the Remote to the BarkRecognizer. This is Doug. He’s not a programmer.

15 What’s wrong with Doug’s idea? 15 You might copy the code incorrectly If you add another type of device you have to copy the code again It’s just plain sloppy and ugly 1 2 3 4 The more copies you have the more you have to change when requirements change

16 Speaking of ugly 16 public class BarkRecognizer { private DogDoor door; public BarkRecognizer(DogDoor door) { this.door = door; } public void recognize(String bark) { System.out.println(" BarkRecognizer: Heard a '" + bark + "'"); door.open(); } This is ugly code

17 This is much better 17 /** * This class represents the bark recognizer that opens the device it * controls if presented with a known bark. * * @author gpollice */ public class BarkRecognizer { private DogDoor door; /** * Constructor initializes this recognizer by storing the device it * controls and the bark it recognizes. * * @param door- door the recognizer controls */ public BarkRecognizer(DogDoor door) { this.door = door; } …

18 18 Woof! (Which means: What’s the purpose of the Bark parameter in the BarkRecognizer?) What is the Bark for? Do we need it? What should we do?

19 Our second release is ready to go ‣ We’ve gone through another iteration ‣ Requirements ‣ Design ‣ Code ‣ Test ‣ We took on a manageable chunk of work ‣ We delivered a working system 19

20 Things to think about ‣ Are the Remote and the BarkRecognizer similar? ‣ Can you encapsulate the similarities? ‣ How would this change the system? ‣ We haven’t implemented a Bark class. How would you do that? ‣ What do we gain from it? 20

21 Time to refactor 21 Modify the code. How is it better?


Download ppt "HFOOAD Chapter 3 Change: the constant in software development."

Similar presentations


Ads by Google