Now, how should we go about learning design patterns?
Should we simply read about them or watch presentations, like this one?
Maybe we should just memorize all their names.
Everyone learns differently,
but I have some recommendations for how you can most effectively learn design
patterns to materially improve your code and your career.
In my own experience with patterns, as well as in other
areas like sports and martial arts,
I found there are distinct stages of learning.
The first stage is simply ignorance.
You don't know that a concept, technique, or pattern exists.
This is where everyone begins, but it's also the
easiest stage from which to progress.
The next stage is what I call awakening.
In this stage,
you become aware of the thing about which you want to learn. Here you might say,
wow, I just learned that the XYZ pattern could help my design.
I'm not really sure how to apply it,
but I'm keen to find out. In this stage, you've probably never actually
applied the pattern; you've only heard about it from others.
Of course, as they say, a little knowledge is a dangerous thing.
And so the next stage is where experimentation and some of the real
learning takes place. Knowing there's a pattern others have found
helpful, you may try to use it everywhere you can.
Generally,
it's less painful to practice new techniques in a controlled
environment rather than in production or on game day.
Eventually, with enough practice,
you'll learn where the pattern fits and where it doesn't
until eventually you reach the final stage.
This stage requires that you actually apply the pattern
yourself in a variety of contexts.
You can't expect to master a pattern you've never actually applied.
However, with mastery, the final stage of learning,
you've internalized the skill or pattern.
You've developed a kind of muscle memory for applying it that
no longer requires you to break down the steps and
consciously go through them one by one.
When you see an opportunity to apply the pattern, you quickly do so and move on.
You also recognize situations where the pattern might seem
a good fit, but you've tried it before,
and you know better now. When considering knowledge or skills,
a common recommendation is to strive to be T‑shaped, like the letter T. That
is, have a broad understanding of general concepts, but also have deep
practical understanding of a few specific things.
It's generally less helpful to only have vague,
encyclopedia‑like knowledge of a wide array of topics, but no ability to
actually deliver anything of value using this knowledge.
It's also not ideal to only have deep understanding of a very
small number of tools or techniques without understanding any
other ways to approach things.
You risk being a one‑trick pony who has a golden
hammer they apply to every problem.
You can apply the concept of T‑shaped knowledge to design patterns as well.
You should at least be familiar with a wide array of patterns.
When someone mentions that they want to use the
observer or flyweight to tackle a problem,
you should immediately recognize that they're referring to a specific pattern.
It's okay if you don't know that pattern intimately,
but your broad knowledge of patterns should let you at
least participate in the discussion.
You'll also know how to find out more about any specific pattern by
quickly watching it's associated Pluralsight course or finding an
appropriate book or online resource.
These patterns you can keep at the awakening knowledge level.
Of course, for those patterns that are most applicable to the
kind of software you deliver,
it'll be very helpful for you to master at least a few of them.
These patterns you might make use of every day,
and you should know them well enough that you can explain how
they're used to new members of your team.
Eventually, the number of patterns you've mastered is likely to grow,
but there will probably always be patterns you don't use often enough to
truly master. Which patterns should you go deep in? Well,
that depends on what kind of applications you're building,
but I'll offer some suggestions at the end of this course.