Patterns
by Charlie Calvert
Preserve Programming Lore
- Experienced programmers have learned there are certain correct ways to solve problems
- Patterns are a record, a means of preserving, this programming lore.
- They preserve a "pattern" that you can follow to create a solution to a frequently encountered programming challenge
A Catalog of Programming Tips
- Another useful metaphor is the idea of a catalog
- A group of patterns represent a catalog of well known solutions to common programming problems.
- There is, of course, nothing new about this.
- But programmers are notoriously unwilling to share information, and here is a group of programmers who have made it their business to share their lore.
Books
- Design Patterns by Erich Gamma et al. Also known as the Gang of Four book, or GOF.
- There are no great writers on this team. However, the lore here is valuable, and the book is parsable if you study it carefully. The book provides an excellent list of things to learn about elsewhere.
- So you can judge for yourself, let me offer an example. Here is the book's definition of the intent of the Composite Pattern: "Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly." These things are a matter of taste. You decide whether you like that definition or not.
- Patterns Home Page
Patterns Improve the Design of an Application
- If you use patterns correctly, then your program will be well architected
- Patterns describe how to architect a portion of an application correctly.
- There is no single pattern for your whole application. But there are common problems inside applications that keep recurring. Patterns record techniques for solving these problems.
Promotes Reusability
- Promotes loose coupling.
- Helps you build independant classes.
Unit Tests Rely on Patterns
- When using NUnit, mock objects solve lots of problems.
- But sometimes it is hard to see how to design loosely coupled code.
- Patterns often explain how to achieve your goal.
- Many patterns promote loose coupling.
Roots in the Architecture of Buildings
- Christopher Alexander created the idea of patterns as a means of sharing lore about designing buildings
- Instead of windows, doors and cornices, we have classes, methods and interfaces.
MVC: Model View Controller
- A classic pattern with which nearly everyone is familiar
Simple, Frequently Used Patterns
Summary
- Patterns aren't sexy.
- This is brute force memorization of proven technologies.
- If you can apply yourself to this dry subject, you will become a better programmer.