Forget Red Bull

24 Apr 2019

Design Patterns are Like Bones

Design patterns are versatile, high-level solutions to certain problems that can be used across a variety of circumstances. Like the arrangement of the bones in the mammalian hand which underlie such various forms as the the wings of a bat, the flippers of a whale, or the precision instruments that I am currently using to type out this very sentence, design patterns allow for many forms and functions, that operate in similar ways under the surface. Some of the advantages of design patterns include readability and shorter development times. In my very limited experience, I will say that, although I am not familiar with most of them, I can recognize that there is utility in the few that I already do.

Writing Code

Code that is hot off the finger presses may work for the time being but will often have unforeseeable consequences down the line. Design patterns are tried and tested templates that have, numerous times, gone through the same process. Through many iterations and across many different projects, design patterns take on a form that tends to avoid those same problems. From the outset, a solution to a problem might seem nebulous or even nonexistent, but ultimately, in each particular instance, the solution crystallizes into some final form. Even though they may be superficially distinct, different solutions to similar problems tend toward a general shape, one that encounters less resistance along the total length of the development process. The hope is that by building within and around this general shape, developers can design solutions which avoid familiar problems and hold up over the course of development. Overall this makes the process more efficient, allowing developers to focus on new problems as they soar to greater heights.

Reading Code

On the other hand, design patterns also make it easier to read code. In their evolutionary history, bats may be distant from birds, but when you look at their wi… ahem, arms for the very first time, without even having to see them fly, you can probably guess what they’re used for. With design patterns, developers can anticipate and recognize similar shapes in the code that gives them an idea of how it works and what it does. In this way, developers don’t have to start from square one when analyzing code they didn’t write.

Conclusion

Personally, one of the design patterns I’ve had the most fun with is the observer design pattern. It took some time and research, but using it I was able to implement a click and drag date range selector. Even though I didn’t, and still don’t, know exactly what is going on when I click a button, I knew just enough to write all of the necessary functions, onMouseUp, onMouseLeave, onMouseDown, and onMouseEnter. If I had been trying to make something else, I would expect the event handler functions to be completely different. In other words, the observer design pattern is specific yet general in a way that allows for versatility with minimal redundancy. In summary, design patterns provide useful templates with a variety of applications.