<p><b>A comprehensive guide to exploring modern Python through data structures, design patterns, and effective object-oriented techniques</b></p><h4>Key Features</h4><ul><li>Build an intuitive understanding of object-oriented design, from introductory to mature programs</li><li>Learn the ins and out
Python Object-Oriented Programming: Build robust and maintainable object-oriented Python applications and libraries
β Scribed by Steven F. Lott, Dusty Phillips
- Publisher
- Packt Publishing
- Year
- 2021
- Tongue
- English
- Leaves
- 715
- Edition
- 4
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
A comprehensive guide to exploring modern Python through data structures, design patterns, and effective object-oriented techniques
Key Features
- Build an intuitive understanding of object-oriented design, from introductory to mature programs
- Learn the ins and outs of Python syntax, libraries, and best practices
- Examine a machine-learning case study at the end of each chapter
Book Description
Python Object-Oriented Programming, Fourth Edition dives deep into the various aspects of OOP, Python as an OOP language, common and advanced design patterns, and hands-on data manipulation and testing of more complex OOP systems. These concepts are consolidated by open-ended exercises, as well as a real-world case study at the end of every chapter, newly written for this edition. All example code is now compatible with Python 3.9+ syntax and has been updated with type hints for ease of learning.
Steven and Dusty provide a friendly, comprehensive tour of important OOP concepts, such as inheritance, composition, and polymorphism, and explain how they work together with Python's classes and data structures to facilitate good design. UML class diagrams are generously used throughout the text for you to understand class relationships. Beyond the book's focus on OOP, it features an in-depth look at Python's exception handling and how functional programming intersects with OOP. Not one, but two very powerful automated testing systems, unittest and pytest, are introduced in this book. The final chapter provides a detailed discussion of Python's concurrent programming ecosystem.
By the end of the book, you will have a thorough understanding of how to think about and apply object-oriented principles using Python syntax and be able to confidently create robust and reliable programs.
What you will learn
- Implement objects in Python by creating classes and defining methods
- Extend class functionality using inheritance
- Use exceptions to handle unusual situations cleanly
- Understand when to use object-oriented features, and more importantly, when not to use them
- Discover several widely used design patterns and how they are implemented in Python
- Uncover the simplicity of unit and integration testing and understand why they are so important
- Learn to statically type check your dynamic code
- Understand concurrency with asyncio and how it speeds up programs
Who this book is for
If you are new to object-oriented programming techniques, or if you have basic Python skills and wish to learn how and when to correctly apply OOP principles in Python, this is the book for you. Moreover, if you are an object-oriented programmer coming from other languages or seeking a leg up in the new world of Python, you will find this book a useful introduction to Python. Minimal previous experience with Python is necessary.
Table of Contents
- Object-Oriented Design
- Objects in Python
- When Objects Are Alike
- Expecting the Unexpected
- When to Use Object-Oriented Programming
- Abstract Base Classes and Operator Overloading
- Python Data Structures
- The Intersection of Object-Oriented and Functional Programming
- Strings, Serialization, and File Paths
- The Iterator Pattern
- Common Design Patterns
- Advanced Design Patterns
- Testing Object-Oriented Programs
- Concurrency
β¦ Table of Contents
Cover
Copyright
Contributors
Table of Contents
Preface
Chapter 1: Object-Oriented Design
Introducing object-oriented
Objects and classes
Specifying attributes and behaviors
Data describes object state
Behaviors are actions
Hiding details and creating the public interface
Composition
Inheritance
Inheritance provides abstraction
Multiple inheritance
Case study
Introduction and problem overview
Context view
Logical view
Process view
Development view
Physical view
Conclusion
Recall
Exercises
Summary
Chapter 2: Objects in Python
Introducing type hints
Type checking
Creating Python classes
Adding attributes
Making it do something
Talking to yourself
More arguments
Initializing the object
Type hints and defaults
Explaining yourself with docstrings
Modules and packages
Organizing modules
Absolute imports
Relative imports
Packages as a whole
Organizing our code in modules
Who can access my data?
Third-party libraries
Case study
Logical view
Samples and their states
Sample state transitions
Class responsibilities
The TrainingData class
Recall
Exercises
Summary
Chapter 3: When Objects Are Alike
Basic inheritance
Extending built-ins
Overriding and super
Multiple inheritance
The diamond problem
Different sets of arguments
Polymorphism
Case study
Logical view
Another distance
Recall
Exercises
Summary
Chapter 4: Expecting the Unexpected
Raising exceptions
Raising an exception
The effects of an exception
Handling exceptions
The exception hierarchy
Defining our own exceptions
Exceptions aren't exceptional
Case study
Context view
Processing view
What can go wrong?
Bad behavior
Creating samples from CSV files
Validating enumerated values
Reading CSV files
Don't repeat yourself
Recall
Exercises
Summary
Chapter 5: When to Use Object-Oriented Programming
Treat objects as objects
Adding behaviors to class data with properties
Properties in detail
Decorators β another way to create properties
Deciding when to use properties
Manager objects
Removing duplicate code
In practice
Case study
Input validation
Input partitioning
The sample class hierarchy
The purpose enumeration
Property setters
Repeated if statements
Recall
Exercises
Summary
Chapter 6: Abstract Base Classes and Operator Overloading
Creating an abstract base class
The ABCs of collections
Abstract base classes and type hints
The collections.abc module
Creating your own abstract base class
Demystifying the magic
Operator overloading
Extending built-ins
Metaclasses
Case study
Extending the list class with two sublists
A shuffling strategy for partitioning
An incremental strategy for partitioning
Recall
Exercises
Summary
Chapter 7: Python Data Structures
Empty objects
Tuples and named tuples
Named tuples via typing.NamedTuple
Dataclasses
Dictionaries
Dictionary use cases
Using defaultdict
Counter
Lists
Sorting lists
Sets
Three types of queues
Case study
Logical model
Frozen dataclasses
NamedTuple classes
Conclusion
Recall
Exercises
Summary
Chapter 8: The Intersection of Object-Oriented and Functional Programming
Python built-in functions
The len() function
The reversed() function
The enumerate() function
An alternative to method overloading
Default values for parameters
Additional details on defaults
Variable argument lists
Unpacking arguments
Functions are objects, too
Function objects and callbacks
Using functions to patch a class
Callable objects
File I/O
Placing it in context
Case study
Processing overview
Splitting the data
Rethinking classification
TheΒ partition()Β function
One-pass partitioning
Recall
Exercises
Summary
Chapter 9: Strings, Serialization, and File Paths
Strings
String manipulation
String formatting
Escaping braces
f-strings can contain Python code
Making it look right
Custom formatters
The format() method
Strings are Unicode
Decoding bytes to text
Encoding text to bytes
Mutable byte strings
Regular expressions
Matching patterns
Matching a selection of characters
Escaping characters
Repeating patterns of characters
Grouping patterns together
Parsing information with regular expressions
Other features of the re module
Making regular expressions efficient
Filesystem paths
Serializing objects
Customizing pickles
Serializing objects using JSON
Case study
CSV format designs
CSV dictionary reader
CSV list reader
JSON serialization
Newline-delimited JSON
JSON validation
Recall
Exercises
Summary
Chapter 10: The Iterator Pattern
Design patterns in brief
Iterators
The iterator protocol
Comprehensions
List comprehensions
Set and dictionary comprehensions
Generator expressions
Generator functions
Yield items from another iterable
Generator stacks
Case study
The Set Builder background
Multiple partitions
Testing
The essential k-NN algorithm
k-NN using the bisect module
k-NN using theΒ heapq module
Conclusion
Recall
Exercises
Summary
Chapter 11: Common Design Patterns
The Decorator pattern
A Decorator example
Decorators in Python
The Observer pattern
An Observer example
The Strategy pattern
A Strategy example
Strategy in Python
The Command pattern
A Command example
The State pattern
A State example
State versus Strategy
The Singleton pattern
Singleton implementation
Case study
Recall
Exercises
Summary
Chapter 12: Advanced Design Patterns
The Adapter pattern
An Adapter example
The FaΓ§ade pattern
A FaΓ§ade example
The Flyweight pattern
A Flyweight example in Python
Multiple messages in a buffer
Memory optimization via Python's slots
The Abstract Factory pattern
An Abstract Factory example
Abstract Factories in Python
The Composite pattern
A Composite example
The Template pattern
A Template example
Case study
Recall
Exercises
Summary
Chapter 13: Testing Object-Oriented Programs
Why test?
Test-driven development
Testing objectives
Testing patterns
Unit testing with unittest
Unit testing with pytest
pytest's setup and teardown functions
pytest fixtures for setup and teardown
More sophisticated fixtures
Skipping tests with pytest
Imitating objects using Mocks
Additional patching techniques
The sentinel object
How much testing is enough?
Testing and development
Case study
Unit testing the distance classes
Unit testing the Hyperparameter class
Recall
Exercises
Summary
Chapter 14: Concurrency
Background on concurrent processing
Threads
The many problems with threads
Shared memory
The global interpreter lock
Thread overhead
Multiprocessing
Multiprocessing pools
Queues
The problems with multiprocessing
Futures
AsyncIO
AsyncIO in action
Reading an AsyncIO future
AsyncIO for networking
Design considerations
A log writing demonstration
AsyncIO clients
The dining philosophers benchmark
Case study
Recall
Exercises
Summary
Packt Page
Other Books You May Enjoy
Index
π SIMILAR VOLUMES
Rethink Python programming with this guide to Python data structures, design patterns and effective object oriented techniques, to uncover a truly modern Python Key Features Stop writing scripts and start architecting programs Learn the latest Python syntax and libraries A practi
Rethink Python programming with this guide to Python data structures, design patterns and effective object oriented techniques, to uncover a truly modern Python Key Features Stop writing scripts and start architecting programs Learn the latest Python syntax and libraries A practica
Rethink Python programming with this guide to Python data structures, design patterns and effective object oriented techniques, to uncover a truly modern Python Key Features Stop writing scripts and start architecting programs Learn the latest Python syntax and libraries A practica