538 kr
Skickas . Fri frakt över 249 kr.
Beskrivning
Improve Your Python Code with Modern Object-Oriented Design Patterns
To write clean, efficient, maintainable code, developers everywhere turn to design patterns. Now there's a Python-specific patterns guide that's friendly and practical enough for every Python developer, regardless of experience.
Best-selling patterns author James W. Cooper presents visual, example-driven explanations of 23 proven patterns for writing superior object-oriented code. Through clear and intuitive code samples, he introduces modern techniques for creating Python objects that interact effectively in powerful, flexible programs. Python newcomers--including those moving from other languages--will find a succinct introduction designed to get them up to speed fast.
Cooper's wide-ranging patterns coverage addresses abstract classes, multiple inheritance, GUI programming and widgets, graphical classes, drawing and plotting, math, databases, Python decorators, images, threads, iterators, creating executable code, and more. Throughout, his informal visual presentation makes patterns far easier to work with--so you can confidently build sophisticated programs that use Python's rich capabilities.
- Review the essentials of Python objects and visual programming
- Learn what design patterns are, and how they help you write better code
- Use creational patterns to enhance flexibility and avoid unnecessary complexity
- Apply structural patterns to ensure that program elements work together well in large programs
- Optimize communication between objects with behavioral patterns
Produktinformation
- Utgivningsdatum:2022-02-23
- Mått:176 x 230 x 20 mm
- Vikt:620 g
- Format:Häftad
- Språk:Engelska
- Antal sidor:352
- Upplaga:1
- Förlag:Pearson Education
- ISBN:9780137579938
Utforska kategorier
Mer om författaren
James W. Cooper holds a PhD in chemistry and worked in academia, for the scientific instrument industry, and for IBM for 25 years, primarily as a computer scientist at IBM's Thomas J. Watson Research Center. Now retired, he is the author of 20 books, including 3 on design patterns in various languages. His most recent books are Flameout: The Rise and Fall of IBM Instruments (2019) and Food Myths Debunked (2014).James holds 11 patents and has written 60 columns for JavaPro Magazine. He has also written nearly 1,000 columns for the now vanished Examiner.com on foods and chemistry, and he currently writes his own blog: FoodScienceInstitute.com. Recently, he has written columns on Python for Medium.com and Substack.He is also involved in local theater groups and is the treasurer for Troupers Light Opera, where he performs regularly.
Innehållsförteckning
- Preface xxiPART I: INTRODUCTION 1The tkinter Library 2GitHub 2Chapter 1 Introduction to Objects 5The Class __init__ Method 6Variables Inside a Class 6Collections of Classes 7Inheritance 8Derived Classes Created with Revised Methods 8Multiple Inheritance 8Drawing a Rectangle and a Square 10Visibility of Variables 12Properties 13Local Variables 13Types in Python 13Summary 14Programs on GitHub 15Chapter 2 Visual Programming in Python 17Importing Fewer Names 19Creating an Object-Oriented Version 19Using Message Boxes 21Using File Dialogs 22Understanding Options for the Pack Layout Manager 23Using the ttk Libraries 24Responding to User Input 25Adding Two Numbers 26Catching the Error 26Applying Colors in tkinter 27Creating Radio Buttons 27Using a Class-Level Variable 30Communicating Between Classes 30Using the Grid Layout 30Creating Checkbuttons 32Disabling Check Boxes 32Adding Menus to Windows 35Using the LabelFrame 39Moving On 40Examples on GitHub 40Chapter 3 Visual Programming of Tables of Data 41Creating a Listbox 42Displaying the State Data 44Using a Combobox 46The Treeview Widget 47Inserting Tree Nodes 50Moving On 51Example Code on GitHub 51Chapter 4 What Are Design Patterns? 53Defining Design Patterns 54The Learning Process 55Notes on Object-Oriented Approaches 56Python Design Patterns 57References 57PART II: CREATIONAL PATTERNS 59Chapter 5 The Factory Pattern 61How a Factory Works 61Sample Code 62The Two Subclasses 62Building the Simple Factory 63Using the Factory 63A Simple GUI 64Factory Patterns in Math Computation 65Programs on GitHub 65Thought Questions 66Chapter 6 The Factory Method Pattern 67The Swimmer Class 68The Event Classes 69Straight Seeding 70Circle Seeding 71Our Seeding Program 72Other Factories 74When to Use a Factory Method 74Programs on GitHub 74Chapter 7 The Abstract Factory Pattern 75A GardenMaker Factory 75How the User Interface Works 77Consequences of the Abstract Factory Pattern 77Thought Questions 78Code on GitHub 78Chapter 8 The Singleton Pattern 79Throwing the Exception 80Creating an Instance of the Class 80Static Classes As Singleton Patterns 81Finding the Singletons in a Large Program 81Other Consequences of the Singleton Pattern 82Sample Code on GitHub 82Chapter 9 The Builder Pattern 83An Investment Tracker 84Calling the Builders 86The List Box Builder 87The Checkbox Builder 88Displaying the Selected Securities 89Consequences of the Builder Pattern 89Thought Questions 89Sample Code on GitHub 89Chapter 10 The Prototype Pattern 91Cloning in Python 91Using the Prototype 92Consequences of the Prototype Pattern 94Sample Code on GitHub 94Chapter 11 Summary of Creational Patterns 95PART III: STRUCTURAL PATTERNS 97Chapter 12 The Adapter Pattern 99Moving Data Between Lists 99Making an Adapter 101The Class Adapter 103Two-Way Adapters 103Pluggable Adapters 103Programs on GitHub 103Chapter 13 The Bridge Pattern 105Creating the User Interface 107Extending the Bridge 108Consequences of the Bridge Pattern 109Programs on GitHub 110Chapter 14 The Composite Pattern 111An Implementation of a Composite 112Salary Computation 112The Employee Classes 112The Boss Class 113Building the Employee Tree 114Printing the Employee Tree 114Creating a Treeview of the Composite 116Using Doubly Linked Lists 117Consequences of the Composite Pattern 118A Simple Composite 119Other Implementation Issues 119Dealing with Recursive Calls 119Ordering Components 120Caching Results 120Programs on GitHub 120Chapter 15 The Decorator Pattern 121Decorating a Button 121Using a Decorator 122Using Nonvisual Decorators 123Decorated Code 124The dataclass Decorator 125Using dataclass with Default Values 126Decorators, Adapters, and Composites 126Consequences of the Decorator Pattern 126Programs on GitHub 127Chapter 16 The Facade Pattern 129Building the Façade Classes 131Creating Databases and Tables 135Using the SQLite Version 136Consequences of the Façade 137Programs on GitHub 137Notes on MySQL 137Using SQLite 138References 138Chapter 17 The Flyweight Pattern 139What Are Flyweights? 139Example Code 140Selecting a Folder 142Copy-on-Write Objects 143Program on GitHub 143Chapter 18 The Proxy Pattern 145Using the Pillow Image Library 145Displaying an Image Using PIL 146Using Threads to Handle Image Loading 146Logging from Threads 149Copy-on-Write 149Comparing Related Patterns 149Programs on GitHub 150Chapter 19 Summary of Structural Patterns 151PART IV: BEHAVIORAL PATTERNS 153Chapter 20 Chain of Responsibility Pattern 155When to Use the Chain 156Sample Code 156The Listboxes 159Programming a Help System 160Receiving the Help Command 161The First Case 162A Chain or a Tree? 163Kinds of Requests 164Consequences of the Chain of Responsibility 164Programs on GitHub 165Chapter 21 The Command Pattern 167When to Use the Command Pattern 167Command Objects 168A Keyboard Example 168Calling the Command Objects 170Building Command Objects 171The Command Pattern 172Consequences of the Command Pattern 172Providing the Undo Function 172Creating the Red and Blue Buttons 175Undoing the Lines 175Summary 176References 176Programs on GitHub 176Chapter 22 The Interpreter Pattern 177When to Use an Interpreter 177Where the Pattern Can Be Helpful 177A Simple Report Example 178Interpreting the Language 179How Parsing Works 180Sorting Using attrgetter() 181The Print Verb 182The Console Interface 182The User Interface 183Consequences of the Interpreter Pattern 184Programs on GitHub 185Chapter 23 The Iterator Pattern 187Why We Use Iterators 187Iterators in Python 187A Fibonacci Iterator 188Getting the Iterator 189Filtered Iterators 189The Iterator Generator 191A Fibonacci Iterator 191Generators in Classes 192Consequences of the Iterator Pattern 192Programs on GitHub 193Chapter 24 The Mediator Pattern 195An Example System 195Interactions Between Controls 197Sample Code 198Mediators and Command Objects 199Consequences of the Mediator Pattern 200Single Interface Mediators 200Programs on GitHub 201Chapter 25 The Memento Pattern 203When to Use a Memento 203Sample Code 204Consequences of the Memento Pattern 209Programs on GitHub 209Chapter 26 The Observer Pattern 211Example Program for Watching Colors Change 212The Message to the Media 215Consequences of the Observer Pattern 215Programs on GitHub 215Chapter 27 The State Pattern 217Sample Code 217Switching Between States 221How the Mediator Interacts with the StateState Transitions 224Programs on GitHub 224Chapter 28 The Strategy Pattern 225Why We Use the Strategy Pattern 225Sample Code 226The Context 227The Program Commands 227The Line and Bar Graph Strategies 228Consequences of the Strategy Pattern 230Programs on GitHub 231Chapter 29 The Template Pattern 233Why We Use Template Patterns 233Kinds of Methods in a Template Class 234Sample Code 234Drawing a Standard Triangle 235Drawing an Isosceles Triangle 236The Triangle Drawing Program 237Templates and Callbacks 238Summary and Consequences 238Example Code on GitHub 238Chapter 30 The Visitor Pattern 239When to Use the Visitor Pattern 239Working with the Visitor Pattern 241Sample Code 241Visiting Each Class 242Visiting Several Classes 242Bosses Are Employees, Too 243Double Dispatching 245Traversing a Series of Classes 245Consequences of the Visitor Pattern 245Example Code on GitHub 245PART V: A BRIEF INTRODUCTION TO PYTHON 247Chapter 31 Variables and Syntax in Python 249Data Types 250Numeric Constants 250Strings 250Character Constants 251Variables 252Complex Numbers 253Integer Division 253Multiple Equal Signs for Initialization 254A Simple Python Program 254Compiling and Running This Program 255Arithmetic Operators 255Bitwise Operators 255Combined Arithmetic and Assignment Statements 256Comparison Operators 256The input Statement 257PEP 8 Standards 258Variable and Function Names 258Constants 258Class Names 258Indentation and Spacing 259Comments 259Docstrings 259String Methods 260Examples on GitHub 261Chapter 32 Making Decisions in Python 263elif is “else if” 263Combining Conditions 264The Most Common Mistake 264Looping Statements in Python 265The for Loop and Lists 265Using range in if Statements 266Using break and continue 266The continue Statement 267Python Line Length 267The print Function 267Formatting Numbers 268C and Java Style Formatting 269The format string Function 269f-string Formatting 269Comma-Separated Numbers 270Strings 270Formatting Dates 271Using the Python match Function 271Pattern Matching 272Reference 273Moving On 273Sample Code on GitHub 273Chapter 33 Development Environments 275IDLE 275Thonny 275PyCharm 276Visual Studio 276Other Development Environments 276LiClipse 276Jupyter Notebook 277Google Colaboratory 277Anaconda 277Wing 278Command-Line Execution 278CPython, IPython, and Jython 278Chapter 34 Python Collections and Files 279Slicing 279Slicing Strings 280Negative Indexes 281String Prefix and Suffix Removal 281Changing List Contents 281Copying a List 282Reading Files 282Using the with Loop 283Handling Exceptions 284Using Dictionaries 284Combining Dictionaries 286Using Tuples 286Using Sets 287Using the map Function 287Writing a Complete Program 288Impenetrable Coding 288Using List Comprehension 289Sample Programs on GitHub 290Chapter 35 Functions 291Returning a Tuple 292Where Does the Program Start? 292Summary 293Programs on GitHub 293Appendix A Running Python Programs 295If You Have Python Installed 295Shortcuts 295Creating an Executable Python Program 296Command-Line Arguments 297Index 299
Mer från samma författare
Label-Free Technologies For Drug Discovery
James Cooper, Matthew Cooper, Lorenz M. Mayr
1 654 kr
Progress in Tourism, Recreation and Hospitality Management, Volume 5
James Cooper, Lockwood, C. P. Cooper, A. Lockwood
1 463 kr
Taxi! Urban Economies and the Social and Transport Impacts of the Taxicab
James Cooper, Ray Mundy
596 kr
Handbook of Public Law and Administration
Phillip J. Cooper, James Cooper, Phillip J. Cooper, Chester A. Newland
835 kr
Du kanske också är intresserad av
- Signerad!
- Nyhet
- Nyhet
- Signerad!
- Nyhet
- Nyhet
- Nyhet
- Nyhet
- Nyhet
- Nyhet
- Nyhet
- Nyhet