BuildingSkillsinOODesign.pdf
(
1767 KB
)
Pobierz
Building Skills in Object-Oriented Design
Release 2.1.1-Python
Steven F. Lott
December 30, 2009
CONTENTS
I
Front Matter
3
1 Preface
5
1.1 Why Read This Book?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Audience
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Organization of This Book
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Why This Subject?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5 Programming Style
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6 Conventions Used in This Book
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.7 Acknowledgements
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 Foundations
13
2.1 Problem Statement
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Our Simulation Application
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Soapbox on Use Cases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Solution Approach
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.5 Methodology, Technique and Process
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
II
Roulette
25
3 Roulette Details
29
3.1 Roulette Game
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2 Available Bets in Roulette
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.3 Some Betting Strategies
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4 Roulette Solution Overview
35
4.1 Preliminary Survey of Classes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2 Preliminary Roulette Class Structure
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.3 A Walkthrough of Roulette
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.4 Roulette Solution Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5 Outcome Class
41
5.1 Outcome Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.2 Design Decision – Object Identity
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.3 Outcome Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.4 Outcome Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.5 Message Formatting
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6 Bin Class
47
i
6.1 Bin Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.2 Design Decision – Choosing A Collection
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.3 Bin Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.4 Bin Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.5 Bin Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7 Wheel Class
51
7.1 Wheel Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.2 Wheel Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.3 Non-Random Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.4 Wheel Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8 Bin Builder Class
55
8.1 Bin Builder Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2 Bin Builder Algorithms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
8.3 BinBuilder Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.4 Bin Builder Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.5 Internationalization and Localization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
9 Roulette Bet Class
61
9.1 Roulette Bet Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
9.2 Design Decision – Create or Locate an Outcome
. . . . . . . . . . . . . . . . . . . . . . . . . 61
9.3 Design Decision – Where to Keep the Outcome Map
. . . . . . . . . . . . . . . . . . . . . . . 62
9.4 Roulette Bet Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
9.5 Roulette Bet Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
9.6 Roulette Bet Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
10 Roulette Table Class
67
10.1 Roulette Table Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
10.2 InvalidBet Exception Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.3 Roulette Table Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10.4 Roulette Table Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11 Roulette Game Class
71
11.1 Roulette Game Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.2 Passenger57 Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11.3 Roulette Game Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.4 Roulette Game Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.5 Roulette Game Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.6 Additional Roulette Design Considerations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
12 Review of Testability
77
12.1 Testability Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
12.2 Test-Driven Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
12.3 Capturing Pseudo-Radom Data
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
12.4 Testability Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
12.5 Testable Random Events Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
12.6 Testability Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
13 Player Class
83
13.1 Roulette Player Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
13.2 Player Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
13.3 Martingale Player Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
13.4 Player Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
ii
14 Overall Simulation Control
89
14.1 Simulation Control Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
14.2 Simulation Terms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
14.3 Simulator Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
14.4 Player Rework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
14.5 Simulation Control Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
15 SevenReds Player Class
95
15.1 SevenReds Player Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
15.2 SevenReds Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
15.3 Player Rework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
15.4 Game Rework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
15.5 SevenReds Player Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
16 Statistical Measures
99
16.1 Statistics Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
16.2 Some Foundations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
16.3 Statistical Algorithms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
16.4 IntegerStatistics Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
16.5 Statistics Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
17 Random Player Class
105
17.1 Random Player Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
17.2 Random Player Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
17.3 Random Player Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
18 Player 1-3-2-6 Class
107
18.1 Player 1-3-2-6 Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
18.2 On Polymorphism
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
18.3 Player 1-3-2-6 Questions and Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
18.4 Player1326 State Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
18.5 Player1326 No Wins Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
18.6 Player1326 One Win Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
18.7 Player1326 Two Wins Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
18.8 Player1326 Three Wins
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
18.9 Player1326 Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
18.10 Player 1-3-2-6 Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
18.11 Advanced Exercise – Refactoring
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
18.12 Advanced Exercise – Less Object Creation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
19 Cancellation Player Class
115
19.1 Cancellation Player Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
19.2 PlayerCancellation Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
19.3 Cancellation Player Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
20 Fibonacci Player Class
117
20.1 Fibonacci Player Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
20.2 PlayerFibonacci Design
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
20.3 Fibonacci Player Deliverables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
21 Conclusion
121
iii
Plik z chomika:
retroman23
Inne pliki z tego folderu:
webapp2-2.2(1).pdf
(430 KB)
werkzeug-docs.zip
(1191 KB)
werkzeug-docs.pdf
(817 KB)
jinja-docs.zip
(256 KB)
jinja-docs.pdf
(377 KB)
Inne foldery tego chomika:
Android - programy
Apologie
Biblia Crosswire
C++
Czcionki
Zgłoś jeśli
naruszono regulamin