Cars and Design Patterns

03 Dec 2020

Before we get into the topic of design patterns, I have one question that I wanted to ask everyone reading this. Let us say that you wanted to enter a small racing circuit, say clubman racing. You want to buy yourself a car that is on a budget but also has a good shell to work with. What would you use? An estate wagon like a Subaru WRX STi Wagon, or something with more sporting credentials like a Volkswagen Corrado VR6? This isn’t a question that is entirely unrelated to what we are discussing; this is something that can be related to just about anything regarding design patterns; amateur league motoring, game design, architecture, and especially programming. The question is, why would we want to use design patterns? Why choose something that we might not think about?

Let us stop talking about programming for just a minute and revisit the question that I asked regarding the two cars. The Subaru Impreza has an All-Wheel-Drive drivetrain, making it an excellent choice for acceleration. The Corrado, on the other hand, has a Front-Wheel-Drive, making for better cornering. Regardless of the choice, both have their ups and downs in terms of performance, not accounting for performance distribution. Additionally, aerodynamics for either car is different (wagon design vs. a sport compact design).

Even when we talk about performance, we also have to look at the cars’ motorsport pedigrees; Subaru has had multiple entries (and victories) in the World Rally Championship (WRC) along with multiple podiums, whereas Volkswagen participated in racing in as early as the late 1950’s. Though should you base your choice off a car’s motorsport history, especially since the performance of the car you are buying could be different on many different levels? Maybe that is a little bit interpretive, seeing that some cars do live up to their predecessor’s reputation.

Now what does this have to do with design patterns and efficiency? Well, design patterns are essentially solutions to efficiency, solutions to getting the best product. In our car example, we wanted to get a used car for clubman racing on a budget, each of which having their own sets of advantages and disadvantages (i.e. drivetrain, price points, design, pedigree). We want to create a fast and efficient solution for our programs, and design patterns help us with that. Some examples of great design patterns include but are not limited to singletons, MVC’s, factories, and observers. Each of these have their own sets of advantages and disadvantages, like our car problem above. An even better example of design patterns includes the use of libraries like “Underscore”, where there are these large methods compacted into one, if not several lines of code. While it will not guarantee fast code, it will help generate effective code. Even the websites that are being developed in my ICS 314 class utilize a type of design pattern to help dish out an effective site.

Design patterns are all around us and each of them fulfill their own separate set of criteria of efficiency, and each solving their own set of unique problems.