O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Redefining Algorithms with the Template Method

Sometimes you have one algorithm that needs to be changed with slight modifications. For example, imagine you are building authentication for some website where you should be able to authenticate users via social network accounts. The authentication processes via Twitter and Facebook, for example, are similar in general but still require some changes; they use different URLs and pass different data. Naively, you implement this algorithm again and again from start to finish, but someday you realize that there are obvious code duplication and difficulties with code maintenance; to change the logic of an algorithm, you need to change your code at several places for every implementation.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required