Intuition and intention: importance of proper design patterns

30 Nov 2023

Introduction

Recently, through a few experiences and conversations I have been encouraged to think more about the quality of the code I write going beyond basic functionality. In addition to being functional, good code should be reproducible, reusable, and easy for another programmer to read and understand. Keeping consistent formatting and structure through coding standards, naming conventions, and design patterns are important practices for writing strong code.

Intentional design for increased usability

Design patterns in particular are important for object creation, program structure, and functionality, especially for larger projects that involve many classes on different levels of relations to each other. As the project becomes more complex, sticking to consistent patterns will save time spent trying to understand old code and refactoring fresh code to fit old designs. The design pattern that should be chosen and adhered to also depends on what the class or program will be expected to do, for example whether it is more important for the object creation process to be easily replicated for multiples of the same object or easily modified to accommodate different attributes. Design patterns are also important to the behaviors of the program, for example deciding whether a state machine or subscription method should be implemented to control a changing variable. These patterns, implemented with regard to the goals of each problem, improve readability, relevancy, and future usability of the code.

Experience builds intuition

When initially drafting code, I don’t write with any specific design patterns in mind. I think it is good to be aware of the different patterns that exist and practice with examples that employ each of them in an efficient and sensible way. There are an infinite number of ways to solve a programming problem, and as an individual, the best structure and design for a project is the one that comes the most naturally. It is important to be educated on the different common types of design patterns so that you can have a fuller arsenal of tools to employ, both alone and when working in groups. The projects that I have worked on so far in my college career employ a wide variety and combination of design patterns, and though it was never intentional on my part, these experiences have given me the skills to recognize these patterns when they are implemented elsewhere, and use my best judgment for what I should choose to implement in personal projects.