Efficiency through Design

02 Dec 2021

Name of the Game: Design Patterns

Let’s Tidy Up Our Code!

In a sense, design patterns will focus on and utilize the strengths of a particular programming language. Those strengths will be a sort of super power that design patterns use creatively in order to solve problems in innovative and more efficient ways than more obvious, but clunkier, implementations with the language. In other words, design patterns wield a language’s strengths creatively in order to make up for its lesser strengths or weaknesses. They might seem intimidating, so the learning curve might be a little steep, and they might take some getting used to. But, in the end, design patterns can help your code to be cleaner and more efficient.

Now, even though specific implementations of design patterns will differ by language (because, after all, each language is unique and will have its own strengths and weaknesses), there are some general categories that many languages’ design patterns can be categorized by.

 

For example, Behavioral Design Patterns involve interactions with objects, such as how they communicate with each other and distribute responsibilities among each other.

 

Meanwhile, Creational Design Patterns involve how objects are created, with flexibility in access, duplication, and modification.

 

Third, Structural Design Patterns involve taking objects and classes as your LEGOs or building blocks, and creating various types of structures out of them.

 

What I Might Try

I am very unfamiliar with the concept of design patterns (researching for and writing this page was a learning process in itself). If I ever did use a design pattern in my programming, then I was unaware of it, and reviewing the various examples online for this topic did not jog any particular memory for me, either.

But, for the sake of discussion, if I were to use a design pattern, then I might use one for C, because C is the programming language that feels the most familiar to me at this point. It also feels very… heavy, compared to the other languages I’ve practiced so far, such as the syntax of print statements. Therefore, I think design patterns for C would feel like a refreshing experience! For example, ( this ) document describes what I find to be a very interesting implementation of a finite state machine in C, by writing the states using C’s feature of allowing pointers to functions. For clarity, the document compares this design pattern with other, less efficient methods (ex. transition tables), and explains the points of efficiency (ex. scaling), too.

Images of Examples for Behavioral, Creational, and Structural Design Patterns provided by: ( link ).