Here’s another primer to help those new to software design patterns . A good start is to say there are three you need to get you head around first, the factory pattern, the singleton pattern and observer pattern.
Q: So what are they?
A: They are strategies as much as they are ways of thinking about how certain groups of classes could be built, their goal is to bring powerful benefits to extending the lifetime of your code.
When you are writing a function, coding on a page perhaps using intellisense, pasting, snippets you may well have several thoughts such as
Is the syntax correct?
Will this do what I want?
Could I have named it better?
There are others but you get my point, design patterns start off in this list somewhere but as your understanding grows they climb to the top of the list.
Only when they are at the top of the list do you know you have truly absorbed them into your coding.
So what’s the big question at the top of the list, here it is!
What design pattern does this piece of code fit into?
That’s all you need to ask,
The piece of code could be a function, sub, class or interface.
If you’re new to software design patterns you can start by asking yourself "have I hard coded the classes my code instantiates or could they be changed at runtime without changing the vast majority of my code?"
If you think you would have to change your code you could benefit from studying the benefits of these 3 primary design patterns.
Of course there are other patterns, each of them are
very powerful strategies to approach particular problems with.
When we share them with other people and use these terms when describing our approach designing solutions we end up with a common terminology. Learning them can often mean going back over some code bases you have already built, the singleton, factory and observer patterns are man made, they don't leap out of the page at you.
What does tend to leap out at you is that much of your existing code may look the same! Be honest, you may have been tempted to cut, past and modify a few functions or subs here and there.
So, are of you ready to dive in for a slighly deeper look at primary design patterns.
If you are already well versed and looking for the latest practical help try this.
Patterns & practices' Web Client Software Factory on CodePlex!An Overview of all major ones is
here