Almost all of us know the GoF patterns. Perhaps not all of the patterns. I forget them from time to time, but with more experience, I remember more and more. (I keep forgetting what a Memento is. )
As important as they are, I think there are other, perhaps more important patterns and principles that I follow. Some of them are “in my head” when I code. Some of them are there and I just follow them without naming.
They are fundamental theorems/patterns/principles of programming.
Good idea to review them.
Good idea to write about them.
Good idea to revisit them.
Don’t you think?
Languages and trends pass by. Principles and how we approach our programming tasks stays with us. Forever.
I’m currently deep into Python. Design patterns I learned earlier still apply. I learned JavaScript a while ago. Same thing.
I feel it’s not the languages we know count. It’s how we go about doing the tasks we have on hand. It’s how we craft software no matter what tools we use. Python is good for one thing; Java for other; and Javascript still for another, but we can apply “our learned way” to all of them.
Once we have solid principles in place, we’re able to reuse it from language to language. Deepening and improving that knowlege has the highest return, I feel.
So I’d like to revisit SOLID principles; GRASP patterns. They’re at the heart of programming. Close to my programming heart, at least. More to follow.
I started learning design patterns a good number of years ago. I learned a few. Probably around half. But others I just kept forgetting. Or I should say, never learned.
C’mon, you did not learn design patterns!
Knowing design patterns is important. Very important. It’s probably the best “tool” in your toolbox as the developer. Not only the Gang of Four (GoF) patterns, which are the most known, but others as well.
But learning design patterns is hard.
It’s not that the design patterns are hard, it’s the process of learning and retaining that’s hard. Why? If you don’t use it… you’ll forget it.
So a month or two ago, I decided to revisit the subject. I decided to learn the Gang of Four (GoF) patterns. Learn it in a way so I can remember. As I said, not an easy thing to do. (I guess I will really know if I learned it after a few months. )
There is probably only one way to really “learn” it. Use it in code. That’s when you see the context, problem, solution, etc. That’s when you really know all the details about the pattern. And most likely it will “stick” with you and you will not forget it.
If you really want to learn a pattern, use it!
If you can…
I have a few that I have used: Observer, Factory, Builder, Singleton, Facade, Strategy, Template Method, Iterator, Command… I think that’s about it.
OK, that’s less than half of the 23 GoF patterns. What happened to the others?
Blame it on my memory.
On the other hand, I don’t want to just use it because it would be cool. It has to be the right fit. And that does not happen often… But when you do see the opportunity, you should be ready!
BE PREPARED
How do you prepare? Here are some ways.
Read the GoF book several times. OK, that might work for you. For others, it probably will not.
Read multiple books. Yes, that’s probably better, but it still could not work for some of the patterns.
Read multiple books and other references at the same time. Yes, I think this is better. Much better. Why? In How To Read A Book the author explains that this is the highest level of reading, Syntopical Reading. By reading multiple authors on the same subject you have trouble understanding, in this case, it might be a particular pattern, you gain the highest level of understanding.
So that’s what I did: I started reading mutliple resources on GoF Patterns at the same time.
Of course, it would be ideal to have ALL the books available on the subject. I don’t. But I have several and that’s a big help. I also have a subscription to Safari (as part of being ACM.org member), and they have a few books there as well. And of course there is the Internet, loaded with many great references.
I started with the classic GoF book. As I read a pattern, let’s say Abstract Factory, I picked up another book or looked at another website. I read a few until I really “got it.” I also looked at code samples. I read some more. Eventually, I got the “aha” moment.
I’d like to share the resources I have used and that I find valuable on the subject of the Design Patterns. Just so your learning will be, let’s say, a bit simpler.
It’s already taken me a long time to get to this point. So without further ado, here they are.
BOOKS
Design Patterns by Gamma,Helm,Johnson,Vlissides
There is a reason it’s the classic book. Start your learning from this book. The explanations, reasoning and usages are the best in this book. But it’s not an easy book to read. In fact, I think it’s hard if you’re not a C++ programmer. Still, it’s a great book.
Refactoring to Patterns by Kerievsky
I appreciate this book more now than when I first bought it. Filled with very good advice. However, it only covers a few of the GoF patterns.
Agile Software Development by Martin
My favorite book. Not on Design Patterns in specific, as it also does not cover all GoF patterns, but still worth checking out the few that it does cover.
Head First Design PatternsAvailable on Safari, this book is loved by many, not so by others (including me). But still a great book on the subject.
WEBSITES
Wikipedia: Design Patterns
More than anything, it contains great examples.
dofactory
(claims to be #1 in design patterns). Valuable resource.
Houston Design Patterns
Great resource on design patterns.
Examples of GoF Patterns
Lists places in the JDK where the patterns are implemented.
INDIVIDUAL PATTERNS
Bridge vs Strategy
If you get stuck like I did, check out this url.
Factory Method
Good examples on how to implement the pattern.