Chapter 1 Basic concepts
1. 1 What is design pattern 2?
1.2 the role of design pattern 3
1.3 classification of grabbing mode 4
1.4 classification of design pattern 4
1.5 learning stage 6
Chapter 2 Responsibility Design Object-Grasp 9
2. 1 information expert 1 1
2.2 creator 13
2.3 low coupling (low coupling) 14
2.4 high cohesion15
2.5 controller 17
2.6 polymorphism (polymorphism) 18
2.7PureFabrication 19
2.8 Indirect (indirect) 20
2.9 Protected Variant (Protected Variant) 2 1
Chapter 3 GoF-Creative Design Patterns 23
3. 1 factory method mode 24
3. 1. 1 Definition 24
3. 1.2 Realistic example-Flag Factory 26
3. 1.3C# Example 1- Electronic Payment System 26
3. 1.4C# Example 2- School Login System 29
3. 1.5Java example-mobile phone simple factory 32
3. 1.6 Advantages and disadvantages 34
3. 1.7 Application Scenario 34
3.2FactoryMethodPattern (factory method mode) 35
3.2. 1 definition 35
3.2.2 Real example-Arsenal 36
3.2.3C# Example-Multi-document System 37
3.2.4Java example-expanding mobile phone factory 4 1
3.2.5 Advantages and Disadvantages 44
The application scenario
3.3 abstract factory (abstract factory) 45
3.3. 1 definition 45
3.3.2 Examples in Real Life-Expanded Arsenal 48
3.3.3C# Example-Continental Ecosystem 49
3.3.4Java instance-computer products 52
3.3.5 Advantages and disadvantages 57
The application scenario
3.4 builder mode (builder mode) 58
3.4. 1 definition 58
3.4.2 Real Example-Fast Food Restaurant 60
3.4.3C# Example-Workshop Automobile Manufacturing 6 1
3.4.4Java Example-Building a House 65
3.4.5 Advantages and disadvantages 69
The application scenario
3.5 Protocol Type Mode 70
3.5. 1 definition 70
3.5.2 Copy and paste 7 1
3.5.3C# Example-Color Manager 72
3.5.4Java Example-Simple Toolbar 74
Shallow copy and deep copy 76
3.5.6 Advantages and disadvantages 82
The application scenario
3.6 Single Mode 82
3.6. 1 Definition
Now 3.6.2? I don't know what to do, indowsTaskManager 83.
3.6.3C# Example-Load Balancing Controller 84
3.6.4Java instance-system log 86
3. 6. 5 Double Check Locking (Double Check Locking) 89
3.6.6 Advantages and Disadvantages 93
Application scenario 93
Chapter 4 GoF- Structured Design Pattern 95
4. 1 adapter mode 96
4. 1. 1 definition 96
4. 1.2 Real example-computer power adapter 97
4. 1.3C# Example-Chemical Database 98
4. 1.4Java example-cleaning system 102
4. 1.5 Advantages and disadvantages 104
4. 1.6 Application Scenario 104
4.2 Bridging Mode (Bridging Mode) 104
4.2. 1 definition 104
4.2.2 Examples in Reality-Men Dating 106
4.2.3C# Example-Business Object and Data Object 107
4.2.4Java example-image processing of different systems 1 12
4.2.5 Advantages and disadvantages 1 14
4.2.6 Application Scenario 1 15
4.3 compound mode (combination mode) 1 15
4.3. 1 Definition 1 15
4.3.2 Practical Application of Combination Mode-Resource Manager 1 17
4.3.3C# Example-Graph Tree Object Structure 1 18
4.3.4Java instance-document format 12 1
4.3.5 Advantages and disadvantages 124
4.3.6 Application Scenario 125
4.4 Decorative pattern (decorative pattern) 125
4.4. 1 definition 125
4.4.2 Decorative Patterns in Reality-Photo Frame 126
4.4.3C# Example-127 in the project library
4.4.4Java instance-custom JButton 13 1
4.4.5 Advantages and disadvantages 133
4.4.6 Application Scenario 134
4.5FacadePattern 134
4.5. 1 definition 134
4.5.2 Examples in Reality-Customer Service 135
4.5.3C# Example-Mortgage Application Review 136
4.5.4Java example-making tea 139
4.5.5 Advantages and disadvantages 143
4.5.6 Application Scenario 143
4.6FlyweightPattern 144
4.6. 1 Definition
4.6.2 Example-Guo Qi in the Middle Reaches of Guo Si 146
4.6.3C# Instance-Document Editor 147
4.6.4Java instance loading image 15 1
4.6.5 Advantages and disadvantages 154
4.6.6 Application Scenario 154
4.7 proxy mode (proxy mode) 154
Definition 154
4.7.2 Several Examples 156
4.7.3C# Example-Mathematical Agent 158
4.7.4Java Instance-Socket Echo 160
4.7.5 Advantages and disadvantages 165
4.7.6 Application Scenario 165
Chapter 5 GoF- Behavior Design Pattern 167
5. 1 responsibility chain (responsibility chain mode) 168
5. 1. 1 definition 168
5. 1.2 Real examples-the transmission of military information 169
5. 1.3C# Example-Purchase Classification Approval 170
5. 1.4Java example-intelligent building security system 174
5. 1.5 Advantages and disadvantages 178
5. 1.6 Application Scenario 178
5.2 command mode (command mode) 179
5.2. 1 definition 179
5.2.2 Example in Reality-Restaurant Reservation 180
5.2.3C# Example-Simple Calculator 18 1
5.2.4Java example-main switch 185
5.2.5 Advantages and disadvantages 189
5.2.6 Application Scenario 189
5.3 Interpreter mode 190
5.3. 1 definition 190
5.3.2 Real examples-music score 192
5.3.3C# Example-China Capital Conversion 192
5.3.4Java instance-custom program interpreter 197
5.3.5 Advantages and disadvantages 204
5.3.6 Application Scenario 205
5.4 Iterator Mode (Iterator Mode) 205
5.4. 1 definition 205
5.4.2 Real Example-TV Program Selector 206
5.4.3C# Example-Traversal Example 207
5.4.4Java instance-two iterators 2 1 1
5.4.5 Advantages and Disadvantages 2 13
5.4.6 Application Scenario 2 14
5.5 Intermediary Mode (Intermediary Mode) 2 14
Definition 2 14
5.5.2 Example-Airport Control Tower 2 15
5.5.3C# Example-Chatroom 2 16
5.5.4Java Example-Multithread Communication 220
5.5.5 Advantages and disadvantages 223
Application scenario 223
5.6 souvenir pattern (souvenir pattern) 223
5.6. 1 Definition
5.6.2 Real Example-Audio Equalizer 226
5.6.3C# Example-Sales Target 226
5.6.4Java instance-Undo operation 23 1
5.6.5 Advantages and disadvantages 236
Application scenario 236
5.7 Observation Mode 236
5.7. 1 definition 236
5.7.2 Real example-bin Laden appeared in 238
5.7.3C# Example-Cat and Mouse 238
5.7.4C# Example-Stock Change 24 1
Java example-monitoring system 245
5.7.6 Advantages and disadvantages 248
Application scenario 248
5.8 State Mode 248
5.8. 1 Definition
5.8.2 Real Example-Good Mood 250
5.8.3C# Example-Account Classification 250
5.8.4Java Example-Car Shift 258
5.8.5 Advantages and Disadvantages 26 1
5.8.6 Application Scenario 26 1
5.9 Strategic Mode 26 1
5.9. 1 definition261
5.9.2 Real-life example-the strategy of going to the airport 263
5.9.3C# Example-Sorting Method 263
5.9.4Java Instance-Multi-format Output 266
5.9.5 Advantages and Disadvantages 272
Application scenario 272
5. 10 template method mode (template method mode) 272
5. 1. 1 definition 272
5. 10.2 Reality Example-Chef Cooking 274
5. 10.3C# Example-Database Connection Template 274
5. 10.4Java example-bubble sorting template 277
5. 10.5 Advantages and disadvantages 280
5. 10.6 Application Scenario 280
5. 1 1 visitor mode 280
5. 1 1. 1 Definition 280
5. 1 1.2 Real Example-Cashier Cashier Invoicing 282
5. 1 1.3C# Example-Personnel Assessment 283
5. 1 1.4Java Example-Maintenance Engineer Inspects Vehicle 287
5. 1 1.5 Advantages and disadvantages 29 1
5. 1 1.6 Application status 29 1
Chapter VI Comprehensive Application of Model 293
6. 1Java instance extension recorder 294
6.2C# Example-Storage Analyzer 298
6.3 Using Schema to Generate Program Architecture 3 16
Appendix 1 self-test question 32 1
Appendix 2 Answers to Self-Test Questions 33 1
Reference 337