万本电子书0元读

万本电子书0元读

顶部广告

Python: Master the Art of Design Patterns电子书

售       价:¥

5人正在读 | 0人评论 6.2

作       者:Dusty Phillips,Chetan Giridhar,Sakis Kasampalis

出  版  社:Packt Publishing

出版时间:2016-09-01

字       数:481.6万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Ensure your code is sleek, efficient and elegant by mastering powerful Python design patterns About This Book Learn all about abstract design patterns and how to implement them in Python 3 Understand the structural, creational, and behavioral Python design patterns Get to know the context and application of design patterns to solve real-world problems in software architecture, design, and application development Discover how to simplify Design Pattern implementation using the power of Python 3 Who This Book Is For If you have basic Python skills and wish to learn in depth how to correctly apply appropriate design patterns, this course is tailor made for you. 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 In Detail Python is an object-oriented *ing 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 Style and approach Advance your Python code through three distinct modules that each build on preceding content. Get the complete coverage of Python design patterns you need to write elegant and efficient code that’s reusable and powerful.
目录展开

Python: Master the Art of Design Patterns

Table of Contents

Python: Master the Art of Design Patterns

Python: Master the Art of Design Patterns

Credits

Preface

What this learning path covers

What you need for this learning path

Who this learning path is for

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Module 1

1. Object-oriented Design

Introducing object-oriented

Objects and classes

Specifying attributes and behaviors

Data describes objects

Behaviors are actions

Hiding details and creating the public interface

Composition

Inheritance

Inheritance provides abstraction

Multiple inheritance

Case study

Exercises

Summary

2. Objects in Python

Creating Python classes

Adding attributes

Making it do something

Talking to yourself

More arguments

Initializing the object

Explaining yourself

Modules and packages

Organizing the modules

Absolute imports

Relative imports

Organizing module contents

Who can access my data?

Third-party libraries

Case study

Exercises

Summary

3. When Objects Are Alike

Basic inheritance

Extending built-ins

Overriding and super

Multiple inheritance

The diamond problem

Different sets of arguments

Polymorphism

Abstract base classes

Using an abstract base class

Creating an abstract base class

Demystifying the magic

Case study

Exercises

Summary

4. Expecting the Unexpected

Raising exceptions

Raising an exception

The effects of an exception

Handling exceptions

The exception hierarchy

Defining our own exceptions

Case study

Exercises

Summary

5. When to Use Object-oriented Programming

Treat objects as objects

Adding behavior 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

Exercises

Summary

6. Python Data Structures

Empty objects

Tuples and named tuples

Named tuples

Dictionaries

Dictionary use cases

Using defaultdict

Counter

Lists

Sorting lists

Sets

Extending built-ins

Queues

FIFO queues

LIFO queues

Priority queues

Case study

Exercises

Summary

7. Python Object-oriented Shortcuts

Python built-in functions

The len() function

Reversed

Enumerate

File I/O

Placing it in context

An alternative to method overloading

Default arguments

Variable argument lists

Unpacking arguments

Functions are objects too

Using functions as attributes

Callable objects

Case study

Exercises

Summary

8. Strings and Serialization

Strings

String manipulation

String formatting

Escaping braces

Keyword arguments

Container lookups

Object lookups

Making it look right

Strings are Unicode

Converting bytes to text

Converting text to bytes

Mutable byte strings

Regular expressions

Matching patterns

Matching a selection of characters

Escaping characters

Matching multiple characters

Grouping patterns together

Getting information from regular expressions

Making repeated regular expressions efficient

Serializing objects

Customizing pickles

Serializing web objects

Case study

Exercises

Summary

9. The Iterator Pattern

Design patterns in brief

Iterators

The iterator protocol

Comprehensions

List comprehensions

Set and dictionary comprehensions

Generator expressions

Generators

Yield items from another iterable

Coroutines

Back to log parsing

Closing coroutines and throwing exceptions

The relationship between coroutines, generators, and functions

Case study

Exercises

Summary

10. Python Design Patterns I

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 state pattern

A state example

State versus strategy

State transition as coroutines

The singleton pattern

Singleton implementation

The template pattern

A template example

Exercises

Summary

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

12. Testing Object-oriented Programs

Why test?

Test-driven development

Unit testing

Assertion methods

Reducing boilerplate and cleaning up

Organizing and running tests

Ignoring broken tests

Testing with py.test

One way to do setup and cleanup

A completely different way to set up variables

Skipping tests with py.test

Imitating expensive objects

How much testing is enough?

Case study

Implementing it

Exercises

Summary

13. Concurrency

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

Using executors to wrap blocking code

Streams

Executors

Case study

Exercises

Summary

2. Module 2

1. Introduction to Design Patterns

Understanding object-oriented programming

Objects

Classes

Methods

Major aspects of object-oriented programming

Encapsulation

Polymorphism

Inheritance

Abstraction

Composition

Object-oriented design principles

The open/close principle

The inversion of control principle

The interface segregation principle

The single responsibility principle

The substitution principle

The concept of design patterns

Advantages of design patterns

Taxonomy of design patterns

Context – the applicability of design patterns

Patterns for dynamic languages

Classifying patterns

Creational patterns:

Structural patterns

Behavioral patterns

Summary

2. The Singleton Design Pattern

Understanding the Singleton design pattern

Implementing a classical Singleton in Python

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

3. The Factory Pattern – Building Factories to Create Objects

Understanding the Factory pattern

The Simple Factory pattern

The Factory Method pattern

Implementing the Factory Method

Advantages of the Factory method pattern

The Abstract Factory pattern

Implementing the Abstract Factory pattern

The Factory method versus Abstract Factory method

Summary

4. The Façade Pattern – Being Adaptive with Façade

Understanding Structural design patterns

Understanding the Façade design pattern

A UML class diagram

Façade

System

Client

Implementing the Façade pattern in the real world

The principle of least knowledge

Frequently asked questions

Summary

5. The Proxy Pattern – Controlling Object Access

Understanding the Proxy design pattern

A UML class diagram for the Proxy pattern

Understanding different types of Proxies

A virtual proxy

A remote proxy

A protective proxy

A smart proxy

The Proxy pattern in the real world

Advantages of the Proxy pattern

Comparing the Façade and Proxy patterns

Frequently asked questions

Summary

6. The Observer Pattern – Keeping Objects in the Know

Introducing Behavioral patterns

Understanding the Observer design pattern

A UML class diagram for the Observer pattern

The Observer pattern in the real world

The Observer pattern methods

The pull model

The push model

Loose coupling and the Observer pattern

The Observer pattern – advantages and disadvantages

Frequently asked questions

Summary

7. The Command Pattern – Encapsulating Invocation

Introducing the Command pattern

Understanding the Command design pattern

A UML class diagram for the Command pattern

Implementing the Command pattern in the real world

Design considerations

Advantages and disadvantages of Command patterns

Frequently asked questions

Summary

8. The Template Method Pattern – Encapsulating Algorithm

Defining the Template Method pattern

Understanding the Template Method design pattern

A UML class diagram for 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

9. Model-View-Controller – Compound Patterns

An introduction to Compound patterns

The Model-View-Controller pattern

Model – knowledge of the application

View – the appearance

Controller – the glue

A UML class diagram for the MVC design pattern

The MVC pattern in the real world

Modules

Benefits of the MVC pattern

Frequently asked questions

Summary

10. The State Design Pattern

Defining the State design pattern

Understanding the State design pattern

Understanding the State design pattern with a UML diagram

A simple example of the State design pattern

The State design pattern with v3.5 implementation

Advantages/disadvantages of the State pattern

Summary

11. AntiPatterns

An introduction to AntiPatterns

Software development AntiPatterns

Spaghetti code

Golden Hammer

Lava Flow

Copy-and-paste or cut-and-paste programming

Software architecture AntiPatterns

Reinventing the wheel

Vendor lock-in

Design by committee

Summary

3. Module 3

1. The Factory Pattern

Factory Method

A real-life example

A software example

Use cases

Implementation

Abstract Factory

A real-life example

A software example

Use cases

Implementation

Summary

2. The Builder Pattern

A real-life example

A software example

Use cases

Implementation

Summary

3. The Prototype Pattern

A real-life example

A software example

Use cases

Implementation

Summary

4. The Adapter Pattern

A real-life example

A software example

Use cases

Implementation

Summary

5. The Decorator Pattern

A real-life example

A software example

Use cases

Implementation

Summary

6. The Facade Pattern

A real-life example

A software example

Use cases

Implementation

Summary

7. The Flyweight Pattern

A real-life example

A software example

Use cases

Implementation

Summary

8. The Model-View-Controller Pattern

A real-life example

A software example

Use cases

Implementation

Summary

9. The Proxy Pattern

A real-life example

A software example

Use cases

Implementation

Summary

10. The Chain of Responsibility Pattern

A real-life example

A software example

Use cases

Implementation

Summary

11. The Command Pattern

A real-life example

A software example

Use cases

Implementation

Summary

12. The Interpreter Pattern

A real-life example

A software example

Use cases

Implementation

Summary

13. The Observer Pattern

A real-life example

A software example

Use cases

Implementation

Summary

14. The State Pattern

A real-life example

A software example

Use cases

Implementation

Summary

15. The Strategy Pattern

A real-life example

A software example

Use cases

Implementation

Summary

16. The Template Pattern

A real-life example

A software example

Use cases

Implementation

Summary

A. Bibliography

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部