piątek, 10 maja 2013

Introduction to design patterns and GoF

This is my first post about Design Patterns in Python.

What exactly is a design pattern?

"A bowl of spaghetti looks twisted
and tangled, which is where
 the name for spaghetti code
 comes from." - Wikipedia
A design pattern is a potentially reusable solution to many programming problems. In most cases, a programmer is coping with a task, which already had been done by someone else. In my understanding of this term, design patterns were found to help to keep code clear, instead of writing spaghetti code.

Let's face it - everybody writes ugly code sometimes or did that in the past. I think that design patterns may be also a way to write the code you're proud of.




Gang of Four (GOF)


The GoF book.
This is the alias for Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, who came up with a book Design Patterns: Elements of Reusable Object-Oriented Software. It was published quite a long time ago (1994), but is still widely recognized by programmers - I've even read an opinion on Stackoverflow, stating that it's the only one book in this topic. (That's not true). In case you're interested - here's the full GoF book: PDF.


A word of warning and encouragement: Don't worry if you don’t understand this book completely on the first reading. We didn’t understand it all on the first writing!

 - GoF 

There are 23 desing patterns described, divided into 3 groups: 

  • Creational (C)
  • Structural (S)
  • Behavioral (B)

It would be hard for me to cover all of them design patterns, so for this blog I'll start with the ones described in the book as "simplest and most common". Here's the list:

  • Abstract Factory (C) (theory, full example)
  • Adapter (S)
  • Composite (S)
  • Decorator (S)
  • Factory Method (C)
  • Observer (B)
  • Strategy  (B)
  • Template Method (B)
I'll probably post also about Singleton (C) and Iterator (B), as they are widely used in many programming languages.

Stay tuned, first design pattern examples in Python coming soon!

Brak komentarzy:

Prześlij komentarz