Skip to Content
Mastering Python Design Patterns - Second Edition
book

Mastering Python Design Patterns - Second Edition

by Kamon Ayeva, Sakis Kasampalis
August 2018
Intermediate to advanced
248 pages
5h 51m
English
Packt Publishing
Content preview from Mastering Python Design Patterns - Second Edition

Real-world examples

Reaching an airport to catch a flight is a good Strategy example used in real life:

  • If we want to save money and we leave early, we can go by bus/train
  • If we don't mind paying for a parking place and have our own car, we can go by car
  • If we don't have a car but we are in a hurry, we can take a taxi

There are trade-offs between cost, time, convenience, and so forth.

In software, Python's sorted() and list.sort() functions are examples of the Strategy pattern. Both functions accept a named parameter key, which is basically the name of the function that implements a sorting strategy [Python 3 Patterns, Recipes, and Idioms, by Bruce Eckel-08, page 202].

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python Design Patterns - Second Edition - Second Edition

Learning Python Design Patterns - Second Edition - Second Edition

Chetan Giridhar, Gennadiy Zlobin

Publisher Resources

ISBN: 9781788837484Supplemental Content