Jump to ratings and reviews
Rate this book

Learning Python Design Patterns

Rate this book

Design pattern is a well-known approach to solve some specific problems which each software developer comes across during his work. Design patterns capture higher-level constructs that commonly appear in programs. If you know how to implement the design pattern in one language, typically you will be able to port and use it in another object-oriented programming language.

The choice of implementation language affects the use of design patterns. Naturally, some languages are more applicable for certain tasks than others. Each language has its own set of strengths and weaknesses. In this book, we introduce some of the better known design patterns in Python. You will learn when and how to use the design patterns, and implement a real-world example which you can run and examine by yourself.

You will start with one of the most popular software architecture patterns which is the Model- View-Controller pattern. Then you will move on to learn about two creational design patterns which are Singleton and Factory, and two structural patterns which are Facade and Proxy. Finally, the book also explains three behavioural patterns which are Command, Observer, and Template.

Approach

This book takes a tutorial-based and user-friendly approach to covering Python design patterns. Its concise presentation means that in a short space of time, you will get a good introduction to various design patterns.

Who this book is for

If you are an intermediate level Python user, this book is for you. Prior knowledge of Python programming is essential. Some knowledge of UML is also required to understand the UML diagrams which are used to describe some design patterns.

100 pages, Paperback

First published January 1, 2013

17 people are currently reading
96 people want to read

About the author

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
4 (10%)
4 stars
15 (39%)
3 stars
17 (44%)
2 stars
2 (5%)
1 star
0 (0%)
Displaying 1 - 10 of 10 reviews
Profile Image for John.
120 reviews27 followers
July 4, 2017
I consider this a bad book for 2 reasons

1. It really writes bad python code.. Not at all pythonic.. And really with python, it's not so hard to write good pythonic code.. If you want to teach someone to write good programs, step #1 is to write it in a clear way. Official python documentation has some really good advice on this and there are good books like Writing Idiomatic Python that you buy really cheap. I strongly disagree with books that try to set the reader on a "good software engineer" path but miss the most basic one...

2. It really doesn't focus on the patterns.. It briefly mentions them, uses an example that sometimes is not even appropriate to help the reader and at the end it briefly mentions some work cases to use these patterns.. The only information that might not seem obvious to someone who already has read about design patterns, is how to implement the singleton pattern.. And even there the comparison between the real singleton and the Borg pattern is really shallow (and with mistakes in my version)..

If you haven't read the book Design Patterns: Elements of Reusable Object-Oriented Software please read it and don't spend any money on this book hoping to learn design patterns combined to python language.. There are also other books about python design patterns but I haven't read them to compare/suggest
Profile Image for Uriel Vidal.
126 reviews1 follower
September 27, 2018
Explica muy bien los patrones de diseño, me gustó mucho que generará el UML del patrón y a través de él generará los ejemplos, además el capítulo de los antipatrones es muy bueno ya que hace nos muestra las dos caras de la moneda de los modelos que se usan en software.
Los puntos a que se pueden mejorar del libro son la forma en que explica los primeros patrones, ya que parecieran que no entran en la misma estructura de los demás, es decir, el las últimas explicaciones un modelo explicativo:
Descripción del patrón -> UML -> ejemplo -> variaciones -> anexos (como FAQ o cosas a tomar en cuenta)
Pero en los primeros capítulos cambia el modo explicativo y después de la descripción:
Descripción del patrón -> variaciones -> UML -> ejemplo -> anexos
Este cambió, aunque mínimo, hace que los ejemplos sean muy extensos y se pierda el hilo del patrón general.
A pesar de lo anterior el libro es bastante explicativo, como para tenerlo de referencia.
12 reviews1 follower
Read
August 2, 2019
All major design patterns - MVC, Singleton, observer, command, template, factory, facade - are explained and implemented in Python using language tweaks. A very useful book to read especially before interviews.
Profile Image for Paul Childs.
183 reviews3 followers
March 10, 2017
I read this mostly for the information in the first chapter about MVC. It was a basic introduction, and gave me the gist of what this design pattern was about, but I wouldn't call my new knowledge about it to be comprehensive. I will have to find other sources to learn more about that pattern.

The book is short, only about 100 pages divided up into 7 chapters, so there is not a lot of space to devote to any one design pattern. So if you are looking for something that covers many patterns, but you don't need a lot of depth this could be a good book for you to read.

If you need more information about any one of the patterns in this book then you might not find everything that you are need to learn in this book.
Profile Image for Jascha.
151 reviews
December 7, 2014
This is one of those book that you read twice. When you get it in your hands, you comfortably guess you will get to the last page in forty minutes, before the train enters the station... it's so short! Then, as time passes and you get through the pages, you start thinking that the paragraph you just finished reading was so intense and plenty of knowledge that you will need to get back to it later, without hurry.

The author starts big introducing MVC: a questionable choice. The MVC architectural pattern, which many Python programmers have met through Django, probably deserves a book on its own, rather than a single chapter. This ends up with the reader scratching his head confused rather than illuminated, unless he was exposed to it through some web framework already.

Singletons have the spotlight in the second chapter, a very short chapter but very well explained. Both normal and borg singletons are presented with clear examples. The author doesn't really go easy on the code and expects you to have some very good knowledge of Python Object Oriented Programming. Still, if this book is for intermediate Python programmers, why doesn't the author import the methods he needs instead of importing half the world? Come on, let's get used to some good programming habits!

Chapters three to six are dedicated to Factories and the Facade, Observer and Proxy patterns. Each chapter is a gem that you wanna read over and over and make that knowledge yours. The concepts are so well explained that the only thing I can bitch about are those UML diagrams, probably done in a hurry. They don't really add any value.

This is a good book. Not great, but good.

Don't get fooled by its short size. The pages are not many but they come with lots of interesting things to learn. It should definitely be in the bookshelf of any programmer that wanna taken seriously with Python. Each pattern is first explained with words, then through examples. While I don't like the coding style of the author, I must admit that the code gets to the point and clearly gives you an idea of how the patterns work, given that you understand the syntax.

As usual, you can find more reviews on my personal blog: http://books.lostinmalloc.com. Feel free to pass by and share your thoughts!
5 reviews2 followers
September 4, 2016
One for serious programmers:

If you are reading this review you are probably asking yourself "Do I *need* this book?". First, go read the preface for the book, it's available via PacktLib (1). Then ask yourself what sort of programmer you consider yourself to be (or want to be), an applications programmer or a systems programmer? If the latter then I'll save you some reading and simply say you do need it, so go buy it.

If you're in the former group then realize you're a big beneficiary of software that has itself benefited from design patterns and, possibly without realizing it, you yourself regularly implement one of the most common patterns, that being the "Facade" pattern, AKA "making things simple/simpler". In fact it could be argued that the whole philosophy of Python is realized by the Facade pattern (try "import this" if you have doubts). If you hope to make the transition to systems programmer, or simply want to get a better understanding of the thinking behind the design of many Python modules, then even a little knowledge of design patterns goes a long way. As this book claims in the preface, it's a jump-start into design patterns and one that will improve your Python skills.

The book uses practical examples from the start and if you are a beginner (or like me, need a refresher on a few points) then you will need to do a little extra reading, mainly about some class related conventions and techniques. The book could do with a short chapter for convenience to cover these but this small extra effort on your part will make you a better Python programmer. Check the Packt web site for minor errata, most/all of which have been corrected in the code samples. Finally, some of the code could have been simpler but this is somewhat a matter of taste and excusable if the aim was to be consistent throughout the book (eg, single class methods).

Overall opinion: worthy addition to your library and at a price that is a no-brainer if you want to be a professional programmer and especially considering the potential pay-off.

(1) PacktLib
Profile Image for Matthew.
35 reviews3 followers
June 1, 2015
This is not a terrible book. The problem with it is that it doesn't teach pythonic code. I'm hesitant to rate the book any lower, because it was obviously well crafted and researched and does not in fact contain incorrect information. It's just that the information points you in the direction of design that doesn't reflect what most python developers would call "pythonic". It looks like Java designs made implementable in python, which is not particularly helpful to an intermediate/advanced python developer and teaches beginner python developers many practices that will not be found in codebases that solve similar problems. In any event, for Jython developers who want to write python that looks good when called from their Java code, this book may provide some useful cues.
Profile Image for Joshua Schairbaum.
5 reviews1 follower
July 23, 2014
If you're unfamiliar with design patterns, this is a good introduction to several of them. If you are familiar, this book shows examples in Python, but none of the implementations seemed specific to Python. Overall, a thorough introduction to several of the classic patterns: Observer, Template, Algorithm, etc.
Profile Image for Mohammad Khatib.
7 reviews2 followers
June 30, 2015
I liked the brevity of the book though I feel it lacked on the explanations and examples of how different patterns can be used and where it has already been applied.

In general this might be a good book as a quick reference and quick reminder on how to implement different patterns in Python, I don't think it is a good book to learn design patterns in general.
Displaying 1 - 10 of 10 reviews

Can't find what you're looking for?

Get help and learn more about the design.