Key FeaturesUnderstand the structural, creational, and behavioral Python design patternsGet to know the context and application of design patterns to solve real-world problems in software architecture, design, and application developmentGet practical exposure through sample implementations in Python v3.5 for the design patterns featuredBook DescriptionWith the increasing focus on optimized software architecture and design it is important that software architects think about optimizations in object creation, code structure, and interaction between objects at the architecture or design level. This makes sure that the cost of software maintenance is low and code can be easily reused or is adaptable to change. The key to this is reusability and low maintenance in design patterns.
Building on the success of the previous edition, Learning Python Design Patterns, Second Edition will help you implement real-world scenarios with Python's latest release, Python v3.5.
We start by introducing design patterns from the Python perspective. As you progress through the book, you will learn about Singleton patterns, Factory patterns, and Facade patterns in detail. After this, we'll look at how to control object access with proxy patterns. It also covers observer patterns, command patterns, and compound patterns.
By the end of the book, you will have enhanced your professional abilities in software architecture, design, and development.
What you will learnEnhance your skills to create better software architectureUnderstand proven solutions to commonly occurring design issuesExplore the design principles that form the basis of software design, such as loose coupling, the Hollywood principle and the Open Close principle among othersDelve into the object-oriented programming concepts and find out how they are used in software applicationsDevelop an understanding of Creational Design Patterns and the different object creation methods that help you solve issues in software developmentUse Structural Design Patterns and find out how objects and classes interact to build larger applicationsFocus on the interaction between objects with the command and observer patternsImprove the productivity and code base of your application using Python design patternsAbout the AuthorChetan Giridhar is a technology leader, open source enthusiast, and Python developer. He has written multiple articles on technology and development practices in magazines such as LinuxForYou and Agile Record, and has published technical papers in the Python Papers journal. He has been a speaker at PyCon conferences such as PyCon India, Asia-Pacific, and New Zealand and loves working on real-time communications, distributed systems, and cloud applications. Chetan has been a reviewer at Packt Publishing and has contributed to books on IPython Visualizations and Core Python.
Table of ContentsIntroduction to Design PatternsThe Singleton Design PatternThe Factory Pattern – Building Factories to Create ObjectsThe Facade Pattern – Being Adaptive with FacadeThe Proxy Pattern – Controlling Object AccessThe Observer Pattern – Keeping Objects in the KnowThe Command Pattern – Encapsulating InvocationThe Template Method Pattern – Encapsulating AlgorithmModel-View-Controller – Compound Patterns</
A very bad book on the topic of design patterns in python.
Where should I begin? I think I should start from explaining where programming design patterns come from. In order to do that, I need to say a few words about another book before I can review this one.
Design patterns were first catalogued and thoroughly described in the iconic book "Design Patterns: Elements of Reusable Object-Oriented Software", written by authors collectively known as the Gang of Four (GoF for short). GoF book did a very good job of listing and explaining all design patterns and providing the reader with real-world examples (that is, examples from software that was actually written, and whose authors documented the problems they had and solutions they found).
However, GoF book mainly targets C++ and Smalltalk, and it's really dated. The core principles described in the book stay the same, but some implementations can be simplified (due to the modern changes made to C++ language standard), and thus the book needs some editing to provide value for modern C++ programmers.
And, of course, if you use language other than C++ (or Smalltalk), you should rely on tools provided by your language. Thus, solutions provided for C++ are usually not very useful for python, due to the many differences between these languages. This explains the need for a new book that would describe python design patterns and illustrate them with pythonic implementations.
So this is what the book being reviewed should deliver. It promises to do so, but fails miserably.
The book claims to provide us with "real-world scenarios". When I see "real-world scenarios", I instantly start thinking about code that has at least some resemblance to real world software, that is, something that may potentially run in production. It doesn't have to be 100% realistic, as this is an educational book, and I am not asking to quote the entirety of GitHub, but still, I think it is possible to take some existing software, analyze relations between classes and objects in this software, and write examples that resemble something that would be written in real life. You know, kind of like GoF did in their book.
But no, the author has something completely different on his mind. By "real-world scenarios", author means "some situation that happens in real life, not necessarily in the software world". For example, the author illustrates that Facade design pattern is essentially like a real-life wedding ceremony... with you being the client, various service providers (florist, hotelier, musician, etc.) being the subsytems, and Facade being the event manager who handles all the subsystems to make all the marriage arrangements.
Actually, this is a good example to illustrate the idea behind the pattern, but this is very far from being a "real-world scenario" in terms of software. It's even worse when author illustrates abstract factories using pizza places as an example. The code provided is ugly, and it's very unlikely you'll ever see something like this in "real-world scenarios".
By the way, It's so ironic to see non-pythonic code in a python book... It's ok when authors omit some PEP8 requirements (for example, blank lines) and WARN THE READERS THEY DO SO for some reason (to prevent number of pages from bloating, for example). But the author names his methods with mixedCase, which is not compliant with PEP8. What does PEP8 say on the topic? "Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility". Since the author, presumably, wrote the book from scratch, and in the modern day and age, there was no excuse to violate PEP8.
And oh, almost forgot. The author feels the urgent need to recap material we learned so often, I can safely claim that approx. 40% of book material is written with the intent of making the book look bigger than it originally was. If you take an arbitrary chapter, it starts with 1) short recap of previous chapter 2) some useless blabber about what we're going to learn 3) the actual material, that is really scarce, and 4) recap of what we read. So, in general, if you read a chapter, you're going to see a recap at the end of this chapter, in the beginning of the next one, and in the form of some useless chit-chat right before the material begins, I kid you not. Some people say that repeating material is essential to learning it. No. In case of this book, all these recaps are so mind-numbingly dumb, it is unlikely you will find any real information between those recaps, and it actually renders all the provided points absolutely useless.
Recaps, recaps everywhere. Ugly code. Real-world scenarios related to weddings and pizzas, not to real-world software. PEP8 violations. This is the book you didn't deserve.
Does this book have any value? Well, if you're completely new to design patterns, it may be of some use to you to get acquainted with design patterns, but I still don't recommend it for all of the reasons listed above. Instead, google "python design patterns github" - you will find an absolutely recap-less collection of design patterns implemented in python. And, if you really intend to understand the idea behind design patterns, learn some C++ and read the GoF book. It's still good.
And speaking of this book - avoid it. Too much water and too little information, definitely not worth the money.
While the examples in the book are (sort of) adequate, the overall quality is what I'd expect from a series of blog posts - it's littered with spelling mistakes and typos. While I accept that the author's first language probably isn't English, these kinds of things should have been picked up by the editor. The book just doesn't flow very well at all and is pretty hard to read as a result.
As noted previously, the examples are okay, but they're not explained particularly well and in many cases are overly contrived. Sure, it can difficult sometimes to come up with a solid real world example but I'd expect better from a book. In addition, some of the coding choices are a bit odd - for example, the book clearly (and repeatedly) points out that it's using Python 3.5, but the print() statements use the Python 2.x style.
Overall, I would avoid this book. I read this to refresh my memory on a few of the patterns and so I had the benefit of already being familiar with the subject matter and I still found it confusing at times. I imagine that someone trying to learn how to apply these to Python for the first time would find it particularly difficult to follow along.
This is a book cobbled together from postings and internet writings and the like. It's almost painful.
Further, it hasn't been proofread "in python the concept of encapculsation is not implicit" with the 'not' being incorrect - the direct opposite is true. Also "clients can't change an object's internal state directly" and then "of course, accessibility can be made private by affixing __ in the variable name'.
All round, a very, very shitty book. It looks like a series of (badly written) lecture notes.
Книгу не рекомендую. Во-первых, очень поверхностная, лишь мазками пробегает по отдельным паттернам. Целостной картины не выходит. Во-вторых, порой автор чересчур усложняет описание либо, наоборот, упрощает его до примитивных понятий, слабо соотносящихся с практикой. Золотой середины, увы, не удалось найти.
Usei este livro na tradução em português como referência para as aulas de linguagem de programação onde ensinei tópicos de orientação a objetos com Python. O livro é ok como referência para implementação de padrões usando Python, é legal para pegar algumas sacadas de metaprogramação e expressões idiomáticas do Python, mas o desenvolvimento do texto é horrível.