Python Object-Oriented Programming: Build robust and maintainable object-oriented Python applications and libraries, 4th Edition
- Length: 714 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2021-07-02
- ISBN-10: 1801077266
- ISBN-13: 9781801077262
- Sales Rank: #271357 (See Top 100 Books)
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.
Preface Who this book is for What this book covers To get the most out of this book Get in touch 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 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 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 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 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 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 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 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 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 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 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 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 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 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 Other Books You May Enjoy Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Python Object-Oriented Programming: Build robust and maintainable object-oriented Python applications and libraries, 4th Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
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.