The wording in that article is quite unfortunate, because it could be interpreted to mean "find well-known software patterns, and stitch them together to create a working application." That is an approach commonly used by inexperienced developers, and it works, provided you understand the patterns, how to apply them properly, and what their appropriate use case is. Inexperienced developers often reach for this approach too soon, before they fully understand the implications.
Experienced developers are capable of creating their own code patterns.
By way of explanation, I'll provide an example. Let's say you have the following code:
string text;
switch (number)
{
case 1:
text = "alpha";
break;
case 2:
text = "bravo";
break;
case 3:
text = "charlie";
break;
...etc.
}
In C#, this can be simplified by putting it into a function, because the break
statements are eliminated. So the code now becomes:
switch (number)
{
case 1: return "alpha";
case 2: return "bravo";
case 3: return "charlie";
...etc.
}
Of course, the real win is when you recognize that this doesn't have to be a switch
statement at all. Instead, you can create a Dictionary:
var words = new Dictionary<int, string>
{
{ 1, "alpha" },
{ 2, "bravo" },
{ 3, "charlie" }
...etc
}
and now you can just say
var word = words[2]; // bravo
This is more powerful than a switch statement, for several reasons:
The dictionary doesn't have to be hard-coded, like the switch statement does. You can choose to load the dictionary from any compatible data source (including XML configuration files, a database or even a remote data feed), and it will still produce values the same way.
You can add new key/value pairs to the dictionary, or delete values that are no longer needed, at runtime. It doesn't have to be a fixed list.
The dictionary will scale better (it will maintain good performance even if it has a large number of entries).
The Dictionary is a powerful software pattern that has a wide range of uses. It is a generalized data structure; you can choose the types it operates on, and be guaranteed a certain level of performance from it. You can even have dictionaries of dictionaries.
For larger data storage and retrieval jobs, the experienced developer knows to reach for a database, because it's proven technology that provides certain guarantees about the way it works.
This is what the blog post means by "write code for patterns, not specific instances."