Spaghetti Code No Longer: Design Patterns

04 Dec 2024

Get it? Because ‘patterns’?

What Are They?

Design patterns in software are solutions for common problems in software development. They aren’t necessarily the final solution as they aren’t implemented code, instead, they are patterns which allow for the creation of software using industry standards. One of the primary uses of design patterns are in object oriented programming.

They often come in 3 different categories: creational, structural, and behavioral. As the names suggest, creational refers to the creation of an object and its initialization with some examples being abstract factories: creating a family of objects or singleton, creating only one instance of a class and no other. Structural design patterns are about creating larger functions, structures, or objects from other classes and objects via composition. Examples include Facade’s which is kind of like putting a bunch of functions together into a single function or overriding functions, further extending their capabilities. Lastly, behavioral design patterns deals with how objects communicate amongst one another. Examples include observers, in which an object that is dependent on another is notified should that object change or mediators which communicates between classes.

Why Bother?

Design patterns are the solutions that have been proven tried-and-true solutions to common problems in software design. Because of this, developers don’t need to worry about having to innovate new ideas or methods for a problem that occurs often. Furthermore, they aren’t tied down to a single problem or function but a bunch of common issues. Because of the nature of coming across a type of problem so many times, they have become efficient in the sense that the patterns designed are already at peak performance. Overall, it’s a time saver and allows for an industry wide standard friendly to all developers.

My Use of Design Patterns

I’ve unknowingly used a bunch of design patterns for this class. I usually knew the concept of what some things were but I didn’t necessarily boil it down to design patterns. I’ve used singletons, creating only a single instance of a class, allowing for access wherever. I’ve used it in creation of the database for my final project for 314, having a database shared between our teammates that we can all access from our own devices. I’ve done builder patterns, creating various user interfaces with different components like add, list, edit, and landing pages! Another design pattern used was the Model-View-Controller design, which is essentially making an application with different uses, like it’s UI (view) and user input (Controller). This is prominent in the digits exercises I’ve done where we basically make react, bootstrap, and nextJs applications. Overall, super useful seeing the different design patterns that are available to us.