Archive for the 'Python' Category

18
Apr
13

Resource Acquisition is Initialization (RAII)

This post will be about the Resource Acquisition is Initialization (RAII) pattern which is a creational pattern. This is going to be the first non Gang of Four pattern I will write about.

The Purpose

The idea behind this pattern is to correctly dispose of all the resources that you acquire. This pattern was first written about by Bjarne Stroustrup, the creator of C++. The most common examples of this pattern are in opening and closing files and web sockets. It is also important in controlling mutexes so you can write tread safe code.

Continue reading ‘Resource Acquisition is Initialization (RAII)’

22
Feb
13

Iterator Pattern

This post will be about the Iterator pattern which is a behavioural pattern.

The Purpose

The idea behind this pattern is to have an object which you can loop over without needing to know the internal representation of the data. While in python nothing is private so you can find out the internals of the class, the iterator pattern gives you a standard interface.

Continue reading ‘Iterator Pattern’

21
Jan
13

Builder Pattern

This post will be about the Builder pattern which is a creational pattern.

The Purpose

The idea behind the builder pattern is to abstract away the construction of an object so that many implementations can use the same builder. This separates the construction logic of the desired class from it’s representation.

Continue reading ‘Builder Pattern’

21
Jan
13

Strategy Pattern

The strategy pattern is a behavioural design pattern. This means that it is a common communication method between objects and not concerned with how those objects are created or structured.

The Purpose

The idea behind the strategy pattern is to encapsulate the implementation details of an algorithm and make them interchangeable. This gives more flexibility in how an object can be used and enables each algorithm to be tested independently of the calling object.
Continue reading ‘Strategy Pattern’

07
Jan
13

Facade Pattern

This is the first of actual posts in my series on design patterns in python.

This will be about the Facade pattern which is a structural pattern.

The Purpose

The facade pattern is used to make one object with a simple interface represent a complicated system. The problem often occurs in programming where you have a series of interconnected classes where the functions must be called in a certain order or have complicated interdependencies.

This pattern is to give a standard interface to such a system, so you don’t have to rely on reading how you call the system in one of the files or look at example usage.
Continue reading ‘Facade Pattern’

07
Jan
13

Design Patterns in Python

This post is 2 things;

  1. A statement of intent
  2. An apology for inaction

Recently this blog has not been nearly as active as I would like it to be. This is due to many things but mostly me simply being very busy.

So that’s the apology done, now for the statement of intent!

I have intended to write a short e-book about design patterns using the python programming language. This is inspired by the aptly titled Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides who are collectively known as the Gang of Four (GOF).
Continue reading ‘Design Patterns in Python’

18
Oct
12

FizzBuzz

FizzBuzz is variously; a drinking game, a maths game, a way of learning numbers in a foreign language and more importantly (for this blog) a programming kata. The principle of FizzBuzz is a counting and substitution game you count to a limit and replace some numbers with words. In the classic example you replace any number which is divisible by 3 with Fizz and any number divisible by 5 with Buzz, and any number which is divisible by both with FizzBuzz. Continue reading ‘FizzBuzz’

16
Jul
12

Finding Primes: Part II – A Python Implementation

As it is easy to get started I first wrote a prime finding algorithm in Python. I used a very basic algorithm for this. I store a list of prime numbers, and I check the numbers less than the square root of the possible prime, if any are a factor of the number I’m checking then it’s a composite otherwise I append it to the list of prime numbers.

The code for this is on my Box account here. Continue reading ‘Finding Primes: Part II – A Python Implementation’

03
Jul
12

Tkinter

I feel this is going to be a very short one this time. I’ve been testing out various graphical toolkits and I wanted to write about Tkinter. As a windows/linux user I wanted something that was truly cross platform. At work I use WPF and although I am actually more of a fan of it than most, but it does have the huge drawback of only being available on windows. Continue reading ‘Tkinter’

17
Jun
12

Hangman

A short post this time. A few months ago I was looking for a little light distraction and I thought I’d learn Python. After doing all the usual stuff (Hello World, and a few problems from Project Euler) I decided to make a short game. As I’m sure you can tell from the title of this post it was a game of hangman. I made this decision because I found out about the string translate feature in Python and thought that it would be perfect to gradually reveal the word. Continue reading ‘Hangman’




Call Me
Endorse davidcorne on Coderwall

Categories

Copyright


© 2013 by David Corne.

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.