What Are Design Patterns and Why You Should Know It

01 Dec 2022

A design pattern is like a blueprint for building a car

Cars may have slight differences like different colors and different shapes but they all fundamentally solve the same problem and share the same characteristics like having an engine, some wheels, seats, and a steering wheel. When building a new car, you should continue to follow these fundamental solutions like having some wheels and seats. Design patterns are template solutions to solving common problems. You are not inventing something completely new, but instead using a solution already thought out by pros or experts before you. Another example is instead of trying to create a new way to get a car moving, you look at how engines fundamentally work and use that solution to design your tweaked engine specifically for your needs. Using already thought-out, well-made solutions is safer and saves you time.

Design patterns in software engineering

Design patterns are used just like that in software engineering, and they are specifically used for cleaner, safer, and sometimes more powerful code. Design patterns have a name, problem description, solution description, and consequences, and there are three types of object-oriented patterns: creational, structural, and behavioral. Some examples of design patterns include Factory, Singleton, Model-View-Controller (MVC), and Observer. You may or may not have heard any of these but you probably have used some of them before. I have used Factory, Prototype, Observer, and Singleton without even knowing it. For example, I have used the Prototype pattern in JavaScript by simply using a class. This is because when using a class with a function or property inside, that function is placed into the prototype object automatically. I have also used the Observer pattern from doing Meteor publications and subscriptions. Moreover, the MVC may also be especially beneficial for web developers.

Conclusion

Design patterns are there so you don’t have to solve the same common problem, and you should definitely make use of it in your code. You may find them in books or online.