Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Object-Oriented Python

You're reading from   Mastering Object-Oriented Python Build powerful applications with reusable code using OOP design patterns and Python 3.7

Arrow left icon
Product type Paperback
Published in Jun 2019
Publisher Packt
ISBN-13 9781789531367
Length 770 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Steven F. Lott Steven F. Lott
Author Profile Icon Steven F. Lott
Steven F. Lott
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Preface 1. Section 1: Tighter Integration Via Special Methods FREE CHAPTER
2. Preliminaries, Tools, and Techniques 3. The __init__() Method 4. Integrating Seamlessly - Basic Special Methods 5. Attribute Access, Properties, and Descriptors 6. The ABCs of Consistent Design 7. Using Callables and Contexts 8. Creating Containers and Collections 9. Creating Numbers 10. Decorators and Mixins - Cross-Cutting Aspects 11. Section 2: Object Serialization and Persistence
12. Serializing and Saving - JSON, YAML, Pickle, CSV, and XML 13. Storing and Retrieving Objects via Shelve 14. Storing and Retrieving Objects via SQLite 15. Transmitting and Sharing Objects 16. Configuration Files and Persistence 17. Section 3: Object-Oriented Testing and Debugging
18. Design Principles and Patterns 19. The Logging and Warning Modules 20. Designing for Testability 21. Coping with the Command Line 22. Module and Package Design 23. Quality and Documentation 24. Other Books You May Enjoy

What this book covers

In this book, we'll cover three broad areas of advanced Python topics. Each topic will be broken into a series of chapters examining a variety of details.

Section 1, Tighter Integration via Special Methods, looks at object-oriented programming (OOP) techniques in depth and how we can more tightly integrate the class definitions of our applications with Python's built-in features. This section consists of nine chapters, which are as follows:

  • Chapter 1, Preliminaries, Tools, and Techniques, covers some preliminary topics, such as unittest, doctest, docstring, and some special method names.
  • Chapter 2, The _init_() Method, provides us with a detailed description and implementation of the _init_() method. We will examine different forms of initialization for simple objects. Following this, we can explore more complex objects that involve collections and containers.
  • Chapter 3, Integrating Seamlessly – Basic Special Methods, explains, in detail, how we can expand a simple class definition to add special methods. We'll need to take a look at the default behavior inherited from the object so that we can understand what overrides are required and when they're actually required.
  • Chapter 4, Attribute Access, Properties, and Descriptors, explores how default processing works in some detail. Here, we will learn how to decide where and when to override the default behavior. We will also explore descriptors and gain a much deeper understanding of how Python's internals work.
  • Chapter 5, The ABCs of Consistent Design, examines the abstract base classes in the collections.abc module. In this chapter, we'll look at the general concepts behind the various containers and collections that we might want to revise or extend. Similarly, we'll look at the concepts behind the numbers that we might want to implement.
  • Chapter 6, Using Callables and Contexts, uncovers several ways to create context managers using the tools in contextlib. We'll demonstrate a number of variant designs for callable objects. This will show you why a stateful callable object is sometimes more useful than a simple function. We'll also explore how to use some of the existing Python context managers before we dive in and write our own context manager.
  • Chapter 7, Creating Containers and Collections, focuses on the basics of container classes. We'll review the variety of special methods that are involved in creating a container and the various features that containers offer. We'll address extending built-in containers to add features. We'll also look at wrapping built-in containers and delegating methods through the wrapper to the underlying container.
  • Chapter 8, Creating Numbers, covers these essential arithmetic operators: +, -, *, /, //, %, and **. We'll also explore these comparison operators: <, >, <=, >=, ==, and !=. We'll finish by summarizing some of the design considerations that go into extending or creating new numbers.
  • Chapter 9, Decorators and Mixins Cross-Cutting Aspects, covers simple function decorators, function decorators with arguments, class decorators, and method decorators.

Section 2, Object Serialization and Persistence, explores a persistent object that has been serialized to a storage medium; perhaps it's transformed to JSON and written to the filesystem. An ORM layer can store the object in a database. This section examines the alternatives for handling persistence. It contains five chapters, which are as follows:

  • Chapter 10, Serializing and Saving – JSON, YAML, Pickle, CSV, and XML, covers simple persistence using libraries focused on various data representations such as JSON, YAML, pickle, XML, and CSV.
  • Chapter 11, Storing and Retrieving Objects via Shelve, explains basic database operations with Python modules, such as shelve (and dbm).
  • Chapter 12, Storing and Retrieving Objects via SQLite, uncovers the more complex world of SQL and the relational database. Because SQL features don't match OOP features well, we have an impedance mismatch problem. A common solution is to use ORM to allow us to persist a large domain of objects. The SQLAlchemy package will be used as an example of the many ORMs that are available.
  • Chapter 13, Transmitting and Sharing Objects, looks at the HTTP protocol, JSON, YAML, and XML representations to transmit an object.
  • Chapter 14, Configuration Files and Persistence, covers various ways in which a Python application can work with a configuration file.
  • Chapter 15, Design Principles and Patterns, reviews the SOLID design principles. These can help organize high-quality, maintainable Python software by following some best practices.

Section 3, Object-Oriented Testing and Debugging, shows you how to gather data to support and debug your own high-performance programs. It includes information on creating the best possible documentation in order to reduce the confusion and complexity of the support. This section contains the final five chapters, which are as follows:

  • Chapter 16, The Logging and Warning Modules, looks at using the logging and warning modules to create audit information, as well as debugging. Additionally, we'll take a significant step beyond using the print() function.
  • Chapter 17, Designing for Testability, covers designing for testability and demonstrates how to use unittest and doctest.
  • Chapter 18, Coping with the Command Line, looks at using the argparse module to parse options and arguments. We'll take this a step further and use the command design pattern to create program components that can be combined and expanded without resorting to writing shell scripts.
  • Chapter 19, Module and Package Design, covers module and package design. This is a higher-level set of considerations; we'll take a look at related classes in a module and related modules in a package.
  • Chapter 20, Quality and Documentation, explores how we can document our design to create some kind of trust that our software is correct and has been properly implemented.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime