Python: Master the Art of Design Patterns

Ensure your code is sleek, efficient and elegant by mastering powerful Python design patterns
Preview in Mapt

Python: Master the Art of Design Patterns

Dusty Phillips, Chetan Giridhar, Sakis Kasampalis

4 customer reviews
Ensure your code is sleek, efficient and elegant by mastering powerful Python design patterns
Mapt Subscription
FREE
$29.99/m after trial
eBook
$10.00
RRP $67.99
Save 85%
Print + eBook
$84.99
RRP $84.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$10.00
$84.99
$29.99 p/m after trial
RRP $67.99
RRP $84.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


Python: Master the Art of Design Patterns Book Cover
Python: Master the Art of Design Patterns
$ 67.99
$ 10.00
Scala Design Patterns - Second Edition Book Cover
Scala Design Patterns - Second Edition
$ 35.99
$ 10.00
Buy 2 for $20.00
Save $83.98
Add to Cart

Book Details

ISBN 139781787125186
Paperback775 pages

Book Description

Python is an object-oriented scripting language that is used in everything from data science to web development. Known for its simplicity, Python increases productivity and minimizes development time. Through applying essential software engineering design patterns to Python, Python code becomes even more efficient and reusable from project to project.

This learning path takes you through every traditional and advanced design pattern best applied to Python code, building your skills in writing exceptional Python. Divided into three distinct modules, you’ll go from foundational to advanced concepts by following a series of practical tutorials.

Start with the bedrock of Python programming – the object-oriented paradigm. Rethink the way you work with Python as you work through the Python data structures and object-oriented techniques essential to modern Python programming. Build your confidence as you learn Python syntax, and how to use OOP principles with Python tools such as Django and Kivy.

In the second module, run through the most common and most useful design patterns from a Python perspective. Progress through Singleton patterns, Factory patterns, Façade patterns and more all with detailed hands-on guidance. Enhance your professional abilities in in software architecture, design, and development.

In the final module, run through the more complex and less common design patterns, discovering how to apply them to Python coding with the help of real-world examples. Get to grips with the best practices of writing Python, as well as creating systems architecture and troubleshooting issues.

This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  • Python 3 Object-Oriented Programming - Second Edition by Dusty Phillips
  • Learning Python Design Patterns - Second Edition by Chetan Giridhar
  • Mastering Python Design Patterns by Sakis Kasampalis

Table of Contents

Chapter 1: Object-oriented Design
Introducing object-oriented
Objects and classes
Specifying attributes and behaviors
Hiding details and creating the public interface
Composition
Inheritance
Case study
Exercises
Summary
Chapter 2: Objects in Python
Creating Python classes
Modules and packages
Organizing module contents
Who can access my data?
Third-party libraries
Case study
Exercises
Summary
Chapter 3: When Objects Are Alike
Basic inheritance
Multiple inheritance
Polymorphism
Abstract base classes
Case study
Exercises
Summary
Chapter 4: Expecting the Unexpected
Raising exceptions
Case study
Exercises
Summary
Chapter 5: When to Use Object-oriented Programming
Treat objects as objects
Adding behavior to class data with properties
Manager objects
Case study
Exercises
Summary
Chapter 6: Python Data Structures
Empty objects
Tuples and named tuples
Dictionaries
Lists
Sets
Extending built-ins
Queues
Case study
Exercises
Summary
Chapter 7: Python Object-oriented Shortcuts
Python built-in functions
An alternative to method overloading
Functions are objects too
Case study
Exercises
Summary
Chapter 8: Strings and Serialization
Strings
Regular expressions
Serializing objects
Case study
Exercises
Summary
Chapter 9: The Iterator Pattern
Design patterns in brief
Iterators
Comprehensions
Generators
Coroutines
Case study
Exercises
Summary
Chapter 10: Python Design Patterns I
The decorator pattern
The observer pattern
The strategy pattern
The state pattern
The singleton pattern
The template pattern
Exercises
Summary
Chapter 11: Python Design Patterns II
The adapter pattern
The facade pattern
The flyweight pattern
The command pattern
The abstract factory pattern
The composite pattern
Exercises
Summary
Chapter 12: Testing Object-oriented Programs
Why test?
Unit testing
Testing with py.test
Imitating expensive objects
How much testing is enough?
Case study
Exercises
Summary
Chapter 13: Concurrency
Threads
Multiprocessing
Futures
AsyncIO
Case study
Exercises
Summary
Chapter 14: Introduction to Design Patterns
Understanding object-oriented programming
Major aspects of object-oriented programming
Object-oriented design principles
The concept of design patterns
Patterns for dynamic languages
Classifying patterns
Summary
Chapter 15: The Singleton Design Pattern
Understanding the Singleton design pattern
Lazy instantiation in the Singleton pattern
Module-level Singletons
The Monostate Singleton pattern
Singletons and metaclasses
A real-world scenario – the Singleton pattern, part 1
A real-world scenario – the Singleton pattern, part 2
Drawbacks of the Singleton pattern
Summary
Chapter 16: The Factory Pattern – Building Factories to Create Objects
Understanding the Factory pattern
The Simple Factory pattern
The Factory Method pattern
The Abstract Factory pattern
The Factory method versus Abstract Factory method
Summary
Chapter 17: The Façade Pattern – Being Adaptive with Façade
Understanding Structural design patterns
Understanding the Façade design pattern
A UML class diagram
Implementing the Façade pattern in the real world
The principle of least knowledge
Frequently asked questions
Summary
Chapter 18: The Proxy Pattern – Controlling Object Access
Understanding the Proxy design pattern
A UML class diagram for the Proxy pattern
Understanding different types of Proxies
The Proxy pattern in the real world
Advantages of the Proxy pattern
Comparing the Façade and Proxy patterns
Frequently asked questions
Summary
Chapter 19: The Observer Pattern – Keeping Objects in the Know
Introducing Behavioral patterns
Understanding the Observer design pattern
The Observer pattern in the real world
The Observer pattern methods
Loose coupling and the Observer pattern
The Observer pattern – advantages and disadvantages
Frequently asked questions
Summary
Chapter 20: The Command Pattern – Encapsulating Invocation
Introducing the Command pattern
Understanding the Command design pattern
Implementing the Command pattern in the real world
Advantages and disadvantages of Command patterns
Frequently asked questions
Summary
Chapter 21: The Template Method Pattern – Encapsulating Algorithm
Defining the Template Method pattern
The Template Method pattern in the real world
The Template Method pattern – hooks
The Hollywood principle and the Template Method
The advantages and disadvantages of the Template Method pattern
Frequently asked questions
Summary
Chapter 22: Model-View-Controller – Compound Patterns
An introduction to Compound patterns
The Model-View-Controller pattern
A UML class diagram for the MVC design pattern
The MVC pattern in the real world
Benefits of the MVC pattern
Frequently asked questions
Summary
Chapter 23: The State Design Pattern
Defining the State design pattern
A simple example of the State design pattern
Advantages/disadvantages of the State pattern
Summary
Chapter 24: AntiPatterns
An introduction to AntiPatterns
Software development AntiPatterns
Software architecture AntiPatterns
Summary
Chapter 25: The Factory Pattern
Factory Method
Abstract Factory
Summary
Chapter 26: The Builder Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 27: The Prototype Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 28: The Adapter Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 29: The Decorator Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 30: The Facade Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 31: The Flyweight Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 32: The Model-View-Controller Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 33: The Proxy Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 34: The Chain of Responsibility Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 35: The Command Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 36: The Interpreter Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 37: The Observer Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 38: The State Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 39: The Strategy Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 40: The Template Pattern
A real-life example
A software example
Use cases
Implementation
Summary

What You Will Learn

  • Discover what design patterns are and how to apply them to writing Python
  • Implement objects in Python by creating classes and defining methods
  • Separate related objects into a taxonomy of classes and describe the properties and behaviors of those objects via the class interface
  • Understand when to use object-oriented features, and more importantly when not to use them
  • Get to know proven solutions to common design issues
  • Explore the design principles that form the basis of software design, such as loose coupling, the Hollywood principle, and the Open Close principle, among others
  • Use Structural Design Patterns and find out how objects and classes interact to build larger applications
  • Improve the productivity and code base of your application using Python design patterns
  • Secure an interface using the Proxy pattern

Authors

Table of Contents

Chapter 1: Object-oriented Design
Introducing object-oriented
Objects and classes
Specifying attributes and behaviors
Hiding details and creating the public interface
Composition
Inheritance
Case study
Exercises
Summary
Chapter 2: Objects in Python
Creating Python classes
Modules and packages
Organizing module contents
Who can access my data?
Third-party libraries
Case study
Exercises
Summary
Chapter 3: When Objects Are Alike
Basic inheritance
Multiple inheritance
Polymorphism
Abstract base classes
Case study
Exercises
Summary
Chapter 4: Expecting the Unexpected
Raising exceptions
Case study
Exercises
Summary
Chapter 5: When to Use Object-oriented Programming
Treat objects as objects
Adding behavior to class data with properties
Manager objects
Case study
Exercises
Summary
Chapter 6: Python Data Structures
Empty objects
Tuples and named tuples
Dictionaries
Lists
Sets
Extending built-ins
Queues
Case study
Exercises
Summary
Chapter 7: Python Object-oriented Shortcuts
Python built-in functions
An alternative to method overloading
Functions are objects too
Case study
Exercises
Summary
Chapter 8: Strings and Serialization
Strings
Regular expressions
Serializing objects
Case study
Exercises
Summary
Chapter 9: The Iterator Pattern
Design patterns in brief
Iterators
Comprehensions
Generators
Coroutines
Case study
Exercises
Summary
Chapter 10: Python Design Patterns I
The decorator pattern
The observer pattern
The strategy pattern
The state pattern
The singleton pattern
The template pattern
Exercises
Summary
Chapter 11: Python Design Patterns II
The adapter pattern
The facade pattern
The flyweight pattern
The command pattern
The abstract factory pattern
The composite pattern
Exercises
Summary
Chapter 12: Testing Object-oriented Programs
Why test?
Unit testing
Testing with py.test
Imitating expensive objects
How much testing is enough?
Case study
Exercises
Summary
Chapter 13: Concurrency
Threads
Multiprocessing
Futures
AsyncIO
Case study
Exercises
Summary
Chapter 14: Introduction to Design Patterns
Understanding object-oriented programming
Major aspects of object-oriented programming
Object-oriented design principles
The concept of design patterns
Patterns for dynamic languages
Classifying patterns
Summary
Chapter 15: The Singleton Design Pattern
Understanding the Singleton design pattern
Lazy instantiation in the Singleton pattern
Module-level Singletons
The Monostate Singleton pattern
Singletons and metaclasses
A real-world scenario – the Singleton pattern, part 1
A real-world scenario – the Singleton pattern, part 2
Drawbacks of the Singleton pattern
Summary
Chapter 16: The Factory Pattern – Building Factories to Create Objects
Understanding the Factory pattern
The Simple Factory pattern
The Factory Method pattern
The Abstract Factory pattern
The Factory method versus Abstract Factory method
Summary
Chapter 17: The Façade Pattern – Being Adaptive with Façade
Understanding Structural design patterns
Understanding the Façade design pattern
A UML class diagram
Implementing the Façade pattern in the real world
The principle of least knowledge
Frequently asked questions
Summary
Chapter 18: The Proxy Pattern – Controlling Object Access
Understanding the Proxy design pattern
A UML class diagram for the Proxy pattern
Understanding different types of Proxies
The Proxy pattern in the real world
Advantages of the Proxy pattern
Comparing the Façade and Proxy patterns
Frequently asked questions
Summary
Chapter 19: The Observer Pattern – Keeping Objects in the Know
Introducing Behavioral patterns
Understanding the Observer design pattern
The Observer pattern in the real world
The Observer pattern methods
Loose coupling and the Observer pattern
The Observer pattern – advantages and disadvantages
Frequently asked questions
Summary
Chapter 20: The Command Pattern – Encapsulating Invocation
Introducing the Command pattern
Understanding the Command design pattern
Implementing the Command pattern in the real world
Advantages and disadvantages of Command patterns
Frequently asked questions
Summary
Chapter 21: The Template Method Pattern – Encapsulating Algorithm
Defining the Template Method pattern
The Template Method pattern in the real world
The Template Method pattern – hooks
The Hollywood principle and the Template Method
The advantages and disadvantages of the Template Method pattern
Frequently asked questions
Summary
Chapter 22: Model-View-Controller – Compound Patterns
An introduction to Compound patterns
The Model-View-Controller pattern
A UML class diagram for the MVC design pattern
The MVC pattern in the real world
Benefits of the MVC pattern
Frequently asked questions
Summary
Chapter 23: The State Design Pattern
Defining the State design pattern
A simple example of the State design pattern
Advantages/disadvantages of the State pattern
Summary
Chapter 24: AntiPatterns
An introduction to AntiPatterns
Software development AntiPatterns
Software architecture AntiPatterns
Summary
Chapter 25: The Factory Pattern
Factory Method
Abstract Factory
Summary
Chapter 26: The Builder Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 27: The Prototype Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 28: The Adapter Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 29: The Decorator Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 30: The Facade Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 31: The Flyweight Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 32: The Model-View-Controller Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 33: The Proxy Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 34: The Chain of Responsibility Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 35: The Command Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 36: The Interpreter Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 37: The Observer Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 38: The State Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 39: The Strategy Pattern
A real-life example
A software example
Use cases
Implementation
Summary
Chapter 40: The Template Pattern
A real-life example
A software example
Use cases
Implementation
Summary

Book Details

ISBN 139781787125186
Paperback775 pages
Read More
From 4 reviews

Read More Reviews

Recommended for You

Python GUI Programming Cookbook - Second Edition Book Cover
Python GUI Programming Cookbook - Second Edition
$ 39.99
$ 10.00
Python: Deeper Insights into Machine Learning Book Cover
Python: Deeper Insights into Machine Learning
$ 69.99
$ 10.00
Natural Language Processing: Python and NLTK Book Cover
Natural Language Processing: Python and NLTK
$ 67.99
$ 10.00
Python: Penetration Testing for Developers Book Cover
Python: Penetration Testing for Developers
$ 67.99
$ 10.00
OpenCV: Computer Vision Projects with Python Book Cover
OpenCV: Computer Vision Projects with Python
$ 63.99
$ 10.00
Mastering Django: Core Book Cover
Mastering Django: Core
$ 39.99
$ 10.00