在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → Adaptive+Code+via+C#

Adaptive+Code+via+C#

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:34.47M
  • 下载次数:10
  • 浏览次数:111
  • 发布时间:2022-01-20
  • 实例类别:C#语言基础
  • 发 布 人:bighero3
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: C#

同类人气实例

实例介绍

【实例简介】Adaptive Code via C#

【实例截图】

from clipboard

【核心代码】

Contents at a glance
Introduction xv
PART I AN AGILE FOUNDATION
CHAPTER 1 Introduction to Scrum 3
CHAPTER 2 Dependencies and layering 43
CHAPTER 3 Interfaces and design patterns 93
CHAPTER 4 Unit testing and refactoring 125
PART II WRITING SOLID CODE
CHAPTER 5 The single responsibility principle 169
CHAPTER 6 The open/closed principle 207
CHAPTER 7 The Liskov substitution principle 217
CHAPTER 8 Interface segregation 251
CHAPTER 9 Dependency injection 281
PART III ADAPTIVE SAMPLE
CHAPTER 10 Adaptive sample: Introduction 325
CHAPTER 11 Adaptive sample: Sprint 1 337
CHAPTER 12 Adaptive sample: Sprint 2 365
Appendix A: Adaptive tools 379
Appendix B: GitHub code samples online
Index 387
About the author 403
www.it-ebooks.info
This page intentionally left blank
www.it-ebooks.info
vii
What do you think of this book? We want to hear from you!
Microsoft is interested in hearing your feedback so we can continually improve our
books and learning resources for you. To participate in a brief online survey, please visit:
microsoft.com/learning/booksurvey
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv
PART I AN AGILE FOUNDATION
Chapter 1 Introduction to Scrum 3
Scrum versus waterfall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Roles and responsibilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Product owner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Scrum master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Development team . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Pigs and chickens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Artifacts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
The Scrum board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Charts and metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Backlogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The sprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Release planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Sprint planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Daily Scrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Sprint demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Sprint retrospective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Scrum calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Problems with Scrum and Agile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Maladaptive code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
www.it-ebooks.info
viii Contents
Chapter 2 Dependencies and layering 43
The definition of dependency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
A simple example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Modeling dependencies in a directed graph . . . . . . . . . . . . . . . . . . . . . 51
Managing dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Implementations versus interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
The new code smell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Alternatives to object construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
The Entourage anti-pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The Stairway pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Resolving dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Dependency management with NuGet . . . . . . . . . . . . . . . . . . . . . . . . . 77
Layering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Common patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Cross-cutting concerns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Asymmetric layering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Chapter 3 Interfaces and design patterns 93
What is an interface? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Explicit implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Adaptive design patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
The Null Object pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
The Adapter pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
The Strategy pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Further versatility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
Duck-typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Mixins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Fluent interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
www.it-ebooks.info
Contents ix
Chapter 4 Unit testing and refactoring 125
Unit testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
Arrange, Act, Assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
Test-driven development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .130
More complex tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Changing existing code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
A new account type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
PART II WRITING SOLID CODE
Chapter 5 The single responsibility principle 169
Problem statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Refactoring for clarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Refactoring for abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
SRP and the Decorator pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
The Composite pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Predicate decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189
Branching decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Lazy decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .194
Logging decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Profiling decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .196
Asynchronous decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .200
Decorating properties and events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Using the Strategy pattern instead of switch . . . . . . . . . . . . . . . . . . . . . . . . 204
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206
Chapter 6 The open/closed principle 207
Introduction to the open/closed principle . . . . . . . . . . . . . . . . . . . . . . . . . . . .207
The Meyer definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .207
The Martin definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .208
Bug fixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .208
Client awareness. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209
Extension points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209
Code without extension points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209
Virtual methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Abstract methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Interface inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
“Design for inheritance or prohibit it” . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Protected variation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213
Predicted variation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
A stable interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Just enough adaptability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Chapter 7 The Liskov substitution principle 217
Introduction to the Liskov substitution principle . . . . . . . . . . . . . . . . . . . . . . 217
Formal definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
LSP rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Preconditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .220
Postconditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .222
Data invariants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .223
Liskov contract rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Code contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Covariance and contravariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Liskov type system rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
www.it-ebooks.info
Contents xi
Chapter 8 Interface segregation 251
A segregation example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
A simple CRUD interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Multiple interface decoration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Client construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .263
Multiple implementations, multiple instances . . . . . . . . . . . . . . . . . . . 263
Single implementation, single instance . . . . . . . . . . . . . . . . . . . . . . . . .266
The Interface Soup anti-pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Splitting interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .268
Client need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .268
Architectural need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Single-method interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .280
Chapter 9 Dependency injection 281
Humble beginnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
The Task List application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Constructing the object graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Inversion of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Beyond simple injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .306
The Service Locator anti-pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .306
Illegitimate Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
The composition root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Convention over configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322
www.it-ebooks.info
xii Contents
PART III ADAPTIVE SAMPLE
Chapter 10 Adaptive sample: Introduction 325
Trey Research . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
The team . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
The product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Initial backlog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Finding stories in prose. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Story point estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .330
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Chapter 11 Adaptive sample: Sprint 1 337
Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
“I want to create rooms for categorizing conversations.” . . . . . . . . . . . . . . .340
The controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .340
The room repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344
“I want to view a list of rooms that represent conversations.” . . . . . . . . . . .349
“I want to view the messages that have been sent to a room.“ . . . . . . . . . 353
“I want to send plain text messages to other room members.” . . . . . . . . . 356
Sprint demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
First demonstration of Proseware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Sprint retrospective. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .358
What went well? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
What went badly? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .360
Things to change? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Things to keep? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .362
Surprises? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .362
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .363
www.it-ebooks.info
Contents xiii
Chapter 12 Adaptive sample: Sprint 2 365
Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .365
“I want to send markdown that will be correctly formatted.” . . . . . . . . . . .367
“I want to filter message content so that it is appropriate.” . . . . . . . . . . . . . 370
“I want to serve hundreds of users concurrently.” . . . . . . . . . . . . . . . . . . . . . 373
Sprint demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Sprint retrospective. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
What went well? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
What went badly? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377
Things to change? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377
Things to keep? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377
Surprises? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Appendix A: Adaptive Tools 379
Appendix B: GitHub code samples online
Index 387
About the author 403

标签: C#

实例下载地址

Adaptive+Code+via+C#

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警