Archive

Posts Tagged ‘Design Pattern’

The importance of Composition

February 4th, 2009

Many times when we are designing our programs model, first thing most people, including myself, want to start doing is inheriting from other classes. This makes for a nice large hierarchical beast. Not that there is anything wrong with that, but it can lead to certain problems (from my own personal experience, it usually does). With composition, the programmer no longer has to extend from the parent class. You are able to expose only the methods you are interested in. In this article, I really want to discuss the importance of composition. I feel as programmers, many of us find inheritance easier and we often use it without thinking about the repercussions it may bring to us.
Read more…

Best Practices, Design Patterns, Opinion, Random Notes , ,

Template Pattern

April 29th, 2008

In this article I want to discuss the Template Pattern. One of the main reasons why I wanted to talk about it is that it holds a few similarities to the Strategy Pattern (which I recently wrote an article on). At the end of this article, I will discuss the differences between the two in hopes to help you choose what fits best for you.

So what is a Template pattern? A Template is a way for use to define the skeleton of an algorithm in an abstract class. The skeleton for our algorithm is defined within a final method, so the outline cannot change. How these methods are carried out are then defined within the subclasses. When used, it gives an inverted control structure, where the super class calls the subclasses methods. This is also how it became known as the Hollywood Method, or “Don’t call us, We’ll call you.”. So lets take a closer look.
Read more…

Design Patterns

How and when to use Singleton classes

April 20th, 2008

It’s a pretty well known pattern, but I want to discuss what a Singleton class is first. In a nutshell, a Singleton class is a class that will only have one instance of the class. In certain cases, we want to make sure that we cannot instantiate multiple copies of the object, so we limit it to just one copy. Instead of having a public constructor for our class, we use a private constructor. Then we use a public method (usually named getInstance()) to make sure there is only one copy.
Read more…

Best Practices, Design Patterns