Practical Python Design Patterns - Wessel Badenhorst

Practical Python Design Patterns (eBook)

Pythonic Solutions to Common Problems
eBook Download: PDF
2017 | 1st ed.
XVII, 350 Seiten
Apress (Verlag)
978-1-4842-2680-3 (ISBN)
Systemvoraussetzungen
36,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen
Become a better, more productive programmer through a series of projects that will help you deeply understand and master each of the design patterns covered. In this book you will learn to write elegant 'Pythonic' code to solve common programming problems. You will also experience design thinking, by identifying design patterns that would be helpful given a specific problem or situation.

Python is eating the world. In recent years it has become so much more than a mere object-oriented, scripting language. Design patterns help you think of and solve problems in chunks. They help you to stand on the shoulders of the giants who have come before, instead of having to reinvent the wheel.


What You Will Learn
  • Craft cleaner code
  • Increase your effectiveness as a programmer
  • Write more 'Pythonic' code
  • Solve bigger problems
  • Discover optimal solutions to com
mon problems, done in a way that is uniquely 'Pythonic.'


Who This Book Is For 
Programmers who are comfortable with Python. It is also guide for people who have mastered other programming languages and who want to make the transition to Python.



Wessel Badenhorst is deeply passionate about the process of attaining mastery, especially in the field of programming. The combination of a BSc in computer science and extensive experience in the real world gives him a balanced and practical perspective on programming, and the road every programmer must walk.


Become a better, more productive programmer through a series of projects that will help you deeply understand and master each of the design patterns covered. In this book you will learn to write elegant "e;Pythonic"e; code to solve common programming problems. You will also experience design thinking, by identifying design patterns that would be helpful given a specific problem or situation.Python is eating the world. In recent years it has become so much more than a mere object-oriented, scripting language. Design patterns help you think of and solve problems in chunks. They help you to stand on the shoulders of the giants who have come before, instead of having to reinvent the wheel.What You Will LearnCraft cleaner codeIncrease your effectiveness as a programmerWrite more Pythonic codeSolve bigger problemsDiscover optimal solutions to common problems, done in a way that is uniquely PythonicWho This Book Is For Programmers who are comfortable with Python. It is also guide for people who have mastered other programming languages and who want to make the transition to Python.

Wessel Badenhorst is deeply passionate about the process of attaining mastery, especially in the field of programming. The combination of a BSc in computer science and extensive experience in the real world gives him a balanced and practical perspective on programming, and the road every programmer must walk.

Table of Contents 5
About the Author 12
About the Technical Reviewer 13
Acknowledgments 14
Chapter 1: Before We Begin 15
The Masters 15
Becoming a Better Programmer 17
Deliberate Practice 18
Single Focus 19
Rapid Feedback 19
Stretch Yourself 20
Stand on the Shoulders of Giants 21
How Do You Do This? 21
The Ability to Course Correct 22
Systems Thinking 23
Mental Models 23
The Right Tools for the Job 24
Design Patterns as a Concept 25
What Makes a Design Pattern? 25
Classification 26
Creational 26
Structural 26
Behavioral 27
The Tools We Will Be Using 27
How to Read This Book 27
Setting Up Your Python Environment 28
On Linux 28
On Mac 29
On Windows 30
VirtualEnv 31
Editors 32
Atom 33
LightTable 33
PyCharm 33
Vim 33
Emacs 34
Sublime Text 34
Summary 35
Chapter 2: The Singleton Pattern 36
The Problem 36
Enter the Objects 42
Cleaning It Up 45
Exercises 48
Chapter 3: The Prototype Pattern 49
The Problem 49
Beyond the First Steps 49
Base for an Actual Game 50
Implementing the Prototype Pattern 63
Shallow Copy vs. Deep Copy 64
Shallow Copy 65
Dealing with Nested Structures 66
Deep Copy 67
Using What We Have Learned in Our Project 68
Exercises 71
Chapter 4: Factory Pattern 73
Getting Started 73
The Game Loop 75
The Factory Method 80
The Abstract Factory 82
Summary 84
Exercises 85
Chapter 5: Builder Pattern 86
Anti-Patterns 95
A Note on Abstraction 100
Exercises 101
Chapter 6: Adapter Pattern 102
Don’t Repeat Yourself (DRY) 104
Separation of Concern 104
Sample Problem 107
Class Adapter 108
Object Adapter Pattern 109
Duck Typing 110
Implementing the Adapter Pattern in the Real World 111
Parting Shots 113
Exercises 114
Chapter 7: Decorator Pattern 115
The Decorator Pattern 118
Closures 123
Retaining Function __name__ and __doc__ Attributes 124
Decorating Classes 128
Parting Shots 131
Exercises 131
Chapter 8: Facade Pattern 132
Point of Sale Example 132
Systems Evolution 136
What Sets the Facade Pattern Apart 138
Parting Shots 141
Exercises 141
Chapter 9: Proxy Pattern 142
Memoization 142
The Proxy Pattern 145
Remote Proxy 148
Virtual Proxy 148
Protection Proxy 149
Parting Shots 149
Exercises 150
Chapter 10: Chain of Responsibility Pattern 151
Setting Up a WSGI Server 153
Authentication Headers 154
The Chain of Responsibility Pattern 158
Implementing Chain of Responsibility in Our Project 162
A More Pythonic Implementation 167
Parting Shots 172
Exercises 173
Chapter 11: Command Pattern 174
Controlling the Turtle 174
The Command Pattern 176
Parting Shots 184
Exercises 184
Chapter 12: Interpreter Pattern 185
Domain-Specific Languages 185
Advantages of DSLs 189
Disadvantages of DSLs 189
Composite Pattern 194
Internal DSL Implementation Using the Composite Pattern 195
Implementing the Interpreter Pattern 200
Parting Shots 207
Exercises 207
Chapter 13: Iterator Pattern 209
Python Internal Implementation of the Iterator Pattern 212
Itertools 219
Generator Functions 220
Generator Expression 222
Parting Shots 223
Exercises 223
Chapter 14: Observer Pattern 224
Parting Shots 241
Exercises 242
Chapter 15: State Pattern 243
State Pattern 246
Parting Shots 251
Exercises 252
Chapter 16: Strategy Pattern 253
Parting Shots 258
Exercises 259
Chapter 17: Template Method Pattern 260
Parting Shots 272
Exercises 272
Chapter 18: Visitor Pattern 274
The Visitor Pattern 287
Parting Shots 299
Exercises 300
Chapter 19: Model-View-Controller Pattern 301
Model-View-Controller Skeleton 305
Controllers 307
Models 308
Views 308
Bringing It All Together 309
Parting Shots 315
Exercises 316
Chapter 20: Publish–Subscribe Pattern 317
Distributed Message Sender 324
Parting Shots 327
Exercises 328
Appendix ADesign Pattern Quick Reference 329
Quick Checks for the Code 329
Singleton 330
Prototype 331
Factory 331
Builder 332
Adapter 333
Decorator 333
Facade 334
Proxy 335
Chain of Responsibility 336
Alternative 336
Command 337
Composite 338
Interpreter 338
Iterator 339
Alternative 340
Observer 340
State 341
Strategy 342
Template Method 342
Visitor 343
Model–View–Controller 344
Publisher–Subscriber 345
Final Words 346
Index 347

Erscheint lt. Verlag 17.10.2017
Zusatzinfo XVII, 350 p. 1 illus. in color.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Python
Mathematik / Informatik Informatik Software Entwicklung
Mathematik / Informatik Informatik Web / Internet
Schlagworte Design Patterns • object oriented • OO • Practical • programming • Python • UML
ISBN-10 1-4842-2680-1 / 1484226801
ISBN-13 978-1-4842-2680-3 / 9781484226803
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 2,8 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
ein kompakter Einstieg für die Praxis

von Ralph Steyer

eBook Download (2024)
Springer Vieweg (Verlag)
34,99
Arbeiten mit NumPy, Matplotlib und Pandas

von Bernd Klein

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
29,99