Design Patterns in Python

python_tutorials

Introduction

Design Patterns are reusable models for solving known and common problems in software architecture.

They’re best described as templates for dealing with a certain usual situation. An architect might have a template for designing certain kinds of door-frames which he fits into many of his projects, and a software engineer, or software architect, should know templates for solving frequent programming challenges.

A good presentation of a design pattern should include:

  • Name
  • Motivating problem
  • Solution
  • Consequences

Equivalent Problems

If you were thinking that that’s a pretty fuzzy concept, you’d be right. For instance, we could say that the following “pattern” solves all of your problems:

  1. Fetch and prepare the necessary data and other resources
  2. Do the calculations needed and perform the necessary work
  3. Make logs of what you’re doing
  4. Release all resources
  5. ???
  6. Profit

This is an example of thinking too abstract. You can’t really call this a pattern because it’s not really a good model for solving any problem, despite being technically applicable to any of them (including making dinner).

On the other extreme, you can have solutions that are just too concrete to be called a pattern. For instance, you could wonder

To finish reading, please visit source site