Learn how to write Python code that’s more robust, efficient, maintainable, and elegant―whether you’re new to the language or you’ve been coding for years. Python Programming with Design Patterns combines a clear, modern introduction to modern Python with visual, example-driven explanations of 23 proven patterns for writing outstanding object-oriented code. Through these patterns and examples, best-selling patterns author James W. Cooper introduces modern techniques for creating Python objects that interact effectively to make powerful, flexible programs.
Cooper’s wide-ranging coverage includes abstract classes, multiple inheritance, GUI programming and widgets, graphical classes, drawing and plotting, math libraries, database programming, Python decorators, images, threads, iterators, creating executable code from Python programs, and much more. He covers the use of six leading Python development environments, and provides complete downloadable code on Github for every example program.
Throughout, Cooper’s informal, visual presentation makes patterns easier than ever to understand and use―so you can confidently build large, complex programs that benefit from everything Python has to offer.
Cover Page About This eBook Halftitle Page Title Page Copyright Page Pearson’s Commitment to Diversity, Equity, and Inclusion Dedication Page Contents at a Glance Table of Contents Preface Book Organization Register Your Book Acknowledgments About the Author Part I: Introduction The tkinter Library GitHub 1. Introduction to Objects The Class __init__ Method Variables Inside a Class Collections of Classes Inheritance Derived Classes Created with Revised Methods Multiple Inheritance Drawing a Rectangle and a Square Visibility of Variables Types in Python Summary Programs on GitHub 2. Visual Programming in Python Importing Fewer Names Creating an Object-Oriented Version Using Message Boxes Using File Dialogs Understanding Options for the Pack Layout Manager Using the ttk Libraries Responding to User Input Applying Colors in tkinter Creating Radio Buttons Communicating Between Classes Using the Grid Layout Creating Checkbuttons Adding Menus to Windows Using the LabelFrame Moving On Examples on GitHub 3. Visual Programming of Tables of Data Creating a Listbox Using a Combobox The Treeview Widget Moving On Example Code on GitHub 4. What Are Design Patterns? Defining Design Patterns The Learning Process Notes on Object-Oriented Approaches Python Design Patterns References Part II: Creational Patterns 5. The Factory Pattern How a Factory Works Sample Code The Two Subclasses Building the Simple Factory Factory Patterns in Math Computation Programs on GitHub Thought Questions 6. The Factory Method Pattern The Swimmer Class The Event Classes Straight Seeding Our Seeding Program Other Factories When to Use a Factory Method Programs on GitHub 7. The Abstract Factory Pattern A GardenMaker Factory How the User Interface Works Consequences of the Abstract Factory Pattern Thought Questions Code on GitHub 8. The Singleton Pattern Throwing the Exception Creating an Instance of the Class Static Classes As Singleton Patterns Finding the Singletons in a Large Program Other Consequences of the Singleton Pattern Sample Code on GitHub 9. The Builder Pattern An Investment Tracker Calling the Builders Displaying the Selected Securities Consequences of the Builder Pattern Thought Questions Sample Code on GitHub 10. The Prototype Pattern Cloning in Python Using the Prototype Consequences of the Prototype Pattern Sample Code on GitHub 11. Summary of Creational Patterns Part III: Structural Patterns 12. The Adapter Pattern Moving Data Between Lists Making an Adapter Programs on GitHub 13. The Bridge Pattern Creating the User Interface Extending the Bridge Consequences of the Bridge Pattern Programs on GitHub 14. The Composite Pattern An Implementation of a Composite Salary Computation The Employee Classes Building the Employee Tree Printing the Employee Tree Creating a Treeview of the Composite Using Doubly Linked Lists Consequences of the Composite Pattern A Simple Composite Other Implementation Issues Programs on GitHub 15. The Decorator Pattern Decorating a Button Using a Decorator Using Nonvisual Decorators The dataclass Decorator Using dataclass with Default Values Decorators, Adapters, and Composites Consequences of the Decorator Pattern Programs on GitHub 16. The Façade Pattern Building the Façade Classes Creating Databases and Tables Using the SQLite Version Consequences of the Façade Programs on GitHub Notes on MySQL Using SQLite References 17. The Flyweight Pattern What Are Flyweights? Example Code Copy-on-Write Objects Program on GitHub 18. The Proxy Pattern Using the Pillow Image Library Displaying an Image Using PIL Using Threads to Handle Image Loading Logging from Threads Copy-on-Write Comparing Related Patterns Programs on GitHub 19. Summary of Structural Patterns Part IV: Behavioral Patterns 20. Chain of Responsibility Pattern When to Use the Chain Sample Code The Listboxes Programming a Help System Receiving the Help Command The First Case A Chain or a Tree? Kinds of Requests Consequences of the Chain of Responsibility Programs on GitHub 21. The Command Pattern When to Use the Command Pattern Command Objects A Keyboard Example Calling the Command Objects Building Command Objects The Command Pattern Consequences of the Command Pattern Providing the Undo Function Summary References Programs on GitHub 22. The Interpreter Pattern When to Use an Interpreter Where the Pattern Can Be Helpful A Simple Report Example Interpreting the Language How Parsing Works The Console Interface The User Interface Consequences of the Interpreter Pattern Programs on GitHub 23. The Iterator Pattern Why We Use Iterators Iterators in Python A Fibonacci Iterator Filtered Iterators The Iterator Generator A Fibonacci Iterator Generators in Classes Consequences of the Iterator Pattern Programs on GitHub 24. The Mediator Pattern An Example System Interactions Between Controls Sample Code Mediators and Command Objects Consequences of the Mediator Pattern Single Interface Mediators Programs on GitHub 25. The Memento Pattern When to Use a Memento Sample Code Consequences of the Memento Pattern Program on GitHub 26. The Observer Pattern Example Program for Watching Colors Change The Message to the Media Consequences of the Observer Pattern Programs on GitHub 27. The State Pattern Sample Code Switching Between States How the Mediator Interacts with the StateManager Consequences of the State Pattern State Transitions Program on GitHub 28. The Strategy Pattern Why We Use the Strategy Pattern Sample Code The Context The Program Commands The Line and Bar Graph Strategies Consequences of the Strategy Pattern Programs on GitHub 29. The Template Pattern Why We Use Template patterns Kinds of Methods in a Template Class Sample Code The Triangle Drawing Program Templates and Callbacks Summary and Consequences Example Code on GitHub 30. The Visitor Pattern When to Use the Visitor Pattern Working with the Visitor Pattern Sample Code Visiting Several Classes Bosses Are Employees, Too Double Dispatching Traversing a Series of Classes Consequences of the Visitor Pattern Example Code on GitHub Part V: A Brief Introduction to Python 31. Variables and Syntax in Python Data Types Numeric Constants Strings Character Constants Variables Complex Numbers Integer Division Multiple Equal Signs for Initialization A Simple Python Program Compiling and Running This Program Arithmetic Operators Combined Arithmetic and Assignment Statements Comparison Operators The input Statement PEP 8 Standards String Methods Examples on GitHub 32. Making Decisions in Python elif is “else if” Combining Conditions The Most Common Mistake Looping Statements in Python Using break and continue Python Line Length The print Function Formatting Numbers Formatting Dates Using the Python match Function Reference Moving On Sample Code on GitHub 33. Development Environments IDLE Thonny PyCharm Visual Studio Other Development Environments Command-Line Execution CPython, IPython, and Jython 34. Python Collections and Files Slicing Slicing Strings Changing List Contents Copying a List Reading Files Handling Exceptions Using Dictionaries Using Tuples Using Sets Using the map Function Writing a Complete Program Using List Comprehension Sample Programs on GitHub 35. Functions Returning a Tuple Where Does the Program Start? Summary Programs on GitHub Appendix A: Running Python Programs If You Have Python Installed Creating an Executable Python Program Command-Line Arguments Index Code Snippets
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.