Every software engineer out there will have encountered the concepts of Object Oriented Programming (OOPs) pretty early on in their coding journey, after which they’re expected to magically come up with code that is reliable, scalable, and maintainable every single time.
But is this really even possible? To find the right solution through OOPs while juggling all these different parameters for “perfect code”?
Well, if someone were to ask us this before, we would have been sceptical, but not anymore. Software engineers have noticed that there are some very common problems that we generally get stuck with. Problems like:
- How do we create classes?
- How do we instantiate them?
- How do we structure classes together?
- How do they interact with each other?
And over time we have developed templatized solutions for these problems that we can use in our day-to-day coding projects and even in interviews.
WHAT ARE THESE TEMPLATES?
These life-saving templates are what we call Design Patterns – reusable solutions for the problems we encounter in our day-to-day programming. One of the best things about these design patterns is the fact that they are language independent and can be used in any language that supports object orientation.
Having been proven and tested time and time again, design patterns are widely used both for daily programming work as well as for low level design (LLD) in interviews. Oftentimes, you may encounter a situation where a colleague recommends a specific design pattern and voila! Your problems will be solved in a snap. During an interview, if the interviewer instructs you to create a class with specific requirements, you can showcase your understanding and knowledge by stating which design pattern would be a perfect fit.
TYPES OF DESIGN PATTERNS
There are overwhelmingly many design patterns out there, most of which we aren’t expected to know. The basic patterns, the ones that we will find handy on a daily basis, are the ones we dive into today.
Design patterns are broadly categorised into 3 types. The best way to understand them is by starting with the problems that they solve for us.
Creational Design Pattern
When we start to design any kind of system, the first thing we need to do is to create some classes and instantiate them. How do we go about doing this efficiently? Well, there are various Creational Design Patterns that help us do this – Factory, Abstract Factory, Singleton – and we will explore these commonly used patterns in later posts.
Structural Design Pattern
Now after creating the classes and objects, we need to organise them so that they form a single, coherent structure and support functionality. This process of organising them is made easier by Structural Design Patterns such as the Bridge, Adaptive, Composite patterns etc.
Behavioural Design Pattern
What next? Once we’ve put the classes and objects into a single structure, we need to enable the communication/interactions between them – facilitating their behaviour. And thus, we have Behavioural Design Patterns like the Interpreter, Strategy, Observer patterns and so on.
Now that we’ve seen the different types of design patterns and been introduced to some examples of each type, we’ll be covering each of these design patterns in detail across different posts coming up! We’ll explore why we need a specific design pattern, what problem it solves for us, and take a peek at the code implementation as well.
Would you like to watch a video introduction to Design Patterns and hear all about the different types? Check out our video on the official YouTube channel!