Learning Python Design Patterns 2nd Edition Chetan Giridhar pdf download
Learning Python Design Patterns 2nd Edition Chetan Giridhar pdf download
https://ebookname.com/product/learning-python-design-
patterns-2nd-edition-chetan-giridhar/
https://ebookname.com/product/learning-javascript-design-
patterns-addy-osmani/
https://ebookname.com/product/learning-javascript-design-
patterns-a-javascript-and-react-developer-s-guide-2nd-edition-
adnan-osmani/
https://ebookname.com/product/machine-learning-with-spark-and-
python-2nd-edition-michael-bowles/
https://ebookname.com/product/waking-dreaming-being-self-and-
consciousness-in-neuroscience-meditation-and-philosophy-evan-
thompson/
Round up 6 Student s Book 6 Round Up Grammar Practice
3rd Revised edition Edition V. Evans
https://ebookname.com/product/round-up-6-student-s-book-6-round-
up-grammar-practice-3rd-revised-edition-edition-v-evans/
https://ebookname.com/product/materials-degradation-and-its-
control-by-surface-engineering-3rd-edition-andrew-w-batchelor/
https://ebookname.com/product/pioneer-performances-staging-the-
frontier-1st-edition-matthew-rebhorn/
https://ebookname.com/product/the-cbi-skills-and-training-
handbook-2nd-edition-mark-parkinson/
https://ebookname.com/product/the-physics-of-radiology-and-
imaging-1st-edition-k/
The Great Naval Game Britain and Germany in the Age of
Empire Jan Rüger
https://ebookname.com/product/the-great-naval-game-britain-and-
germany-in-the-age-of-empire-jan-ruger/
Learning Python Design Patterns Second
Edition
Table of Contents
Learning Python Design Patterns Second Edition
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
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
Index
Learning Python Design Patterns Second
Edition
Learning Python Design Patterns Second
Edition
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2013
Second edition: February 2016
Production reference: 1080216
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-803-8
www.packtpub.com
Credits
Author
Chetan Giridhar
Reviewer
Maurice HT Ling
Commissioning Editor
Kunal Parikh
Acquisition Editor
Denim Pinto
Content Development Editor
Merint Thomas Mathew
Technical Editor
Chinmay S. Puranik
Copy Editor
Tasneem Fatehi
Project Coordinator
Suzanne Coutinho
Proofreader
Safis Editing
Indexer
Priya Sane
Graphics
Kirk D’Penha
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
Foreword
“Controlling complexity is the essence of computer programming.”
—Brian Kernighan
“All problems in computer science can be solved by another level of indirection (abstraction).”
—David Wheeler
The preceding two quotes by two well known computer scientists illustrate the problem
faced by the modern software designer—coming up with a good, stable, reusable, flexible
solution to a software design problem.
Design patterns solve the preceding problems in the most elegant way. Design patterns
abstract and present in neat, well-defined components and interfaces the experience of
many software designers and architects over many years of solving similar problems.
These are solutions that have withstood the test of time with respect to reusability,
flexibility, scalability, and maintainability.
There have been many books on design patterns with the well-known Gang of Four (GoF)
book forming the cornerstone of nearly the entire domain.
However, in this era of web and mobile computing, where programs tend to get written in
high-level languages such as Python, Ruby, and Clojure, there is often a need for books
that translate the rather esoteric language used in such books into more familiar terms,
with reusable code written in these newer, more dynamic programming languages. This is
especially true when it comes to newbie programmers who often tend to get lost in the
complexities of design versus implementation and often require an expert helping hand.
This book fulfills that role very well. It uses the template of design patterns as laid out in
the GoF book and adds a few others as well for completion—but before jumping into the
patterns itself, gives the young and inexperienced reader the fundamentals of software
design principles that have gone into the thinking behind the creation and evolution of
these design patterns. It doesn’t walk the gentle reader blindly into the maze of the pattern
world, but lays out the fundamentals well before opening that door and carrying the reader
along that path of learning.
The book is written with Python as the language for implementing the sample code for the
patterns—and this makes excellent sense. As someone who has spent more than 12 years
in the company of this wonderful programming language, I can attest to its beauty and
simplicity and its effectiveness in solving problems ranging from routine to the most
complex. Python is ideally suited to the rookie and young programmer, and with the ease
of learning it, it is also a lot of fun to code in. The young programmer would find their
time spent in the company of Python along in this book very rewarding and fruitful.
Chetan Giridhar has been working and contributing to Python for well over 7 years. He is
ideally suited for the job of penning a book like this, as he has gone through some of the
cycles of learning the complexities of implementation and design himself and has learned
well through that process. He is a well-known speaker on a number of varied topics in
Python and has delivered well-attended talks at Python conferences, such as PyCon India.
He was amongst the invited speakers for conferences in the USA, Asia-Pacific, and New
Zealand.
I believe this book, Learning Python Design Patterns, Second Edition, would be an
excellent addition to the Learning series by Packt Publishing and would provide a set of
skills to the toolbox of the young Python programmer that would take them gently and
expertly to being able to design modular and efficient programs in Python.
Anand B Pillai
CTO—Skoov.com
Board Member—Python Software Foundation
Founder—Bangalore Python User’s Group
About the Author
Chetan 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.
I’d like to thank the Packt Publishing team, especially Merint Thomas Mathew, and the
technical reviewer, Maurice HT Ling, for bringing out the best content in this book.
Special thanks to my mentor, Anand B Pillai, for graciously accepting to review this book
and writing the foreword. This book wouldn’t be possible without the blessings of my
parents, Jyotsana and Jayant Giridhar, and constant support and encouragement from my
wife, Deepti, and my daughter, Pihu!
About the Reviewer
Maurice HT Ling has been programming in Python since 2003. Having completed his Ph
D in bioinformatics and B Sc (honors) in molecular and cell biology from The University
of Melbourne, he is currently a research fellow in Nanyang Technological University,
Singapore, and an honorary fellow at The University of Melbourne, Australia. Maurice is
the chief editor for computational and mathematical biology, and co-editor for The Python
Papers. Recently, Maurice cofounded the first synthetic biology startup in Singapore,
AdvanceSyn Pte. Ltd., as a director and chief technology officer. He is also the principal
partner of Colossus Technologies LLP, Singapore. His research interests lie in life—
biological life, artificial life, and artificial intelligence—using computer science and
statistics as tools to understand life and its numerous aspects. In his free time, Maurice
likes to read, enjoy a cup of coffee, write his personal journal, or philosophize on various
aspects of life. You can reach him at his website and on his LinkedIn profile at
http://maurice.vodien.com and http://www.linkedin.com/in/mauriceling, respectively.
www.PacktPub.com
Support files, eBooks, discount offers, and
more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as
a print book customer, you are entitled to a discount on the eBook copy. Get in touch with
us at <service@packtpub.com> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital
book library. Here, you can search, access, and read Packt’s entire library of books.
Another Random Document on
Scribd Without Any Related Topics
The Project Gutenberg eBook of Gli ingenui
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: Italian
GLI INGENUI
MILANO
Casa editrice Galli di C. CHIESA & F. GUINDANI
Galleria Vittorio Emanuele, 17-80
—
1896
PROPRIETÀ LETTERARIA
Tip. Luigi di Giacomo Pirola. — Milano, piazza Scala, 6.
INDICE
La cagna nera
Nora
Da Novi a Pavia
Per un ribelle
ΤΗ ΕΛΠΙΔΙ
La cagna nera
*
* *
Ci volle la conoscenza nuda e cruda della rovina in cui eravamo
piombati per togliermi la benda dagli occhi e farmi prendere una
risoluzione.
Ecco come fu: per Natale, una volta, volli andare a casa a far le feste
con lei: era tanto che non ci era stato e morivo della voglia di
rivederla.
Nevicava, nevicava da parecchi giorni, dì e notte, come ne le fole, a
grandi falde.
Ma era il Natale! Quanti ricordi si congiunsero a quel nome soave!
Ricordai quando tutto il palazzo era in festa, quando v'erano tanti
invitati che dormivano anche ne le stanze del palazzo. Erano parenti,
amici venuti da lontano; mio babbo li voleva tutti vicino a sè in quel
giorno. Egli che volevano portare come progressista e repubblicano
alla deputazione politica, aveva una melanconica religione degli usi e
dei buoni costumi di una volta. Mi ricordo che voleva persino che ne
la nostra cappella si celebrasse la messa di mezzanotte. Ricordo
anche la cucina, con la cappa del camino grande come tutta la
parete. Lui vi scendeva madido di neve con gli stivaloni infangati e la
carabina a tracolla e su la tavola rovesciava il carniere pieno di
selvaggina da lui cacciata, e dava gli ordini alla cuoca che parea
comandasse una carica alla baionetta; e poi v'erano certe
schidionate enormi di capponi che rosolavano al fuoco. Fuori
imbiancava la neve proprio come faceva allora. Giorni soavi!
La memoria di quella giovanezza di cose e di vita mi vinse. Telegrafai
che sarei venuto anche contro la voglia di lei e dissi il giorno e l'ora.
Partii. Ero tutto lieto di passare le feste a casa e fantasticava
giovanilmente in quel tepore che vince durante il viaggio, specie
sedendo come io sedeva su di un soffice divano di prima classe,
ravvolto in una superba pelliccia.
Si giunse. Dal finestrino del vagone, mentre il treno rallentava, aveva
visto una carrozza chiusa, ferma su lo spiazzo deserto che è dietro la
piccola stazione dove si scende per andare su al villaggio. Non ce
n'erano altre. Ma la carrozza e il cavallo non erano i nostri, però
riconobbi Beppo che stava a cassetta. Tutto questo mi meravigliò
con un senso pauroso di presentimento del vero. Il brav'uomo se ne
stava più curvo e più vecchio del solito sotto la neve, e pareva così
assorto che non si avvide nè meno dell'arrivo del treno. Egli era tutto
chiuso in una vecchia livrea verde di famiglia coi paramani d'oro
stinti, ma la carrozza, dico, non era più la nostra; era un fiacre da
nolo di forme preistoriche che stava su a forza di corde, e il cavallo
era così alto e macilento che su quella neve, col muso basso e le
gambe davanti piegate, faceva un effetto spettrale. Indovinai tutto, e
il cuore mi si serrò: pure non chiesi nulla a Beppo. Egli mi salutò
scoprendosi, ma non disse parola; sferzò a parecchie riprese la rozza
che si mosse indolente fra il cigolare delle ruote e delle molle
sconquassate. Quel cavallo e quel fiacre da zingari erranti e quel
servo chiuso ne la livrea gentilizia offrivano un contrasto simbolico e
miserevole. Un borghese democratico ne avrebbe riso a crepapelle,
un filosofo di cuore avrebbe pianto. Per buona sorte non v'era alcuno
per la via, e i pochi villani che si incontravano di tratto in tratto
facevano largo e si arrestavano meravigliati al nostro passaggio; e
da un sommesso parlare pareva si interrogassero se qualche
cerretano giungesse al villaggio.
La strada bianca di neve passava lentamente. Quando su lo sfondo
plumbeo di quel cielo si disegnò il profilo del palazzo di mio padre e
di mia madre, il cuore mi tremò e un singulto mi corse su per il petto
e scoppiò in singhiozzi repressi su la spalliera della carrozza; e poi
piansi a lungo.
Quella bestia slombata quasi di passo e fumando per tutta la pelle,
saliva le giravolte del colle fra la neve e il silenzio che incombevano
sui campi. Il silenzio della neve! Si udiva solo l'ansimare della rozza e
lo scuotersi stridente dei vetri ne' telai sconnessi. Giungemmo. I
quattro cipressi dormivano sotto la neve che li impellicciava, come
sentinelle che non hanno più nulla da custodire. La porta d'ingresso
a vetri si aprì: mia mamma stessa la aprì e mi accolse ridendo
insieme e lagrimando. Mi condusse subito ne la stanza da pranzo
dove ardevano pochi sarmenti: ma alla rigidezza dell'aria si capiva
che da poco tempo era stato acceso quell'etico fuoco. Su la tavola
grande e quadrata la tovaglia di lino si stendeva come una candida
nevicata, chè tutto il ricco vasellame d'argento e di fine cristallo non
c'era più.
Il vento borea della miseria avea spazzato via tutto. Solo in una
antica e preziosa terraglia a fiorami azzurri che l'ingorda ignoranza
dei compratori dovea aver rifiutata, erano due grappoli d'uva con gli
acini tutti vizzi e con alcune mele dalla pelle rugosa e ferrigna.
Io mi sentiva piombare l'angoscia e lo stupore sul capo e pure
pareva che non fosse vero. Vero! e i miei sensi si rifiutavano di
credere. Anche alcuni lembi del damasco che copriva le pareti si
erano slabbrati, e l'umidità e il gelo penetrando attraverso le
screpolature del muro, vi si erano grommati in una specie di muffa;
altri lembi cadevano accartocciati in sè stessi accidiosamente. Mia
madre non si accorgeva o fingeva di non avvedersi di nulla.
Mi fece sedere vicino a sè, attizzò il fuoco, e mi passò il braccio sul
collo. Domandava con premura notizie della contessa B....; che cosa
n'era della figliuola della signora C...., che ella tenne a battesimo.
— Si deve essere fatta carina! Tu le fai la corte, scommetto?
Domandava se la marchesa A.... era sempre così bionda, se dava
ancora quelle feste così ricche che se ne parlava per dei mesi prima
e dei mesi dopo. — Quanto avrei caro di vederla!
Poi cominciò a parlare di me con una volubilità ardente. Io
rispondeva sì e no, ricambiavo i saluti, raccontavo distrattamente,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com