If you are anything like how I was in my college days, you are here now, because you have an upcoming exam or submission regarding Design patterns and you are here to understand them. During class, design patterns seem extremely easy and not worth paying attention to. But that’s where we got it wrong. It starts off very easy and quickly turns into one of the most complicated things that you simply can’t get your head around. There are two ways of doing this, one buy design term papers or second, learn it from scratch right now.
The first method is easy to get done but you also need to answer your viva. So, let’s quickly get to the gist of it. Basically, I am going to quickly tell you what you missed in class and what you must know about design patterns in the shortest way possible.
Design Patterns are needed while writing software code to ensure that the code works well, irrespective of the language used, number of people/ teams working on the project. When implemented correctly, design patterns make life easy, when done wrong, they cause havoc. Design patterns are classified into three major types, viz, structural, creational and behavioural.
Structural patterns deal with relationships between different parts of the code. A bridge pattern connects an object to its implementation, while an adapter converts converts one interface to another. A composite pattern is to create groups of similar items so that they can be treated the same way, while decorator allows you to add functions more dynamically. A façade as the name suggests creates a face for an entire sub system.
Creational patterns are all about how you want to create your product. It can be abstract which a collection of many classes or builder type, where each part of built one by one. A prototype pattern is used when object creation is expensive but cloning is easy whereas in a singleton only one instance is possible.
Behavioural patterns are all about how objects interact with each other. A chain of responsibility passes command from one object to another, whereas a command sends direct orders. An interpreter helps in understanding the language elements, whereas an iterator allows sequential aggregation of objects. As the name suggests, a memento is like a way to remember an object, while an observer keeps track of changes made to data ad updates everything dependent on it. Strategy helps you define one, whereas a template just gives a guidemap and allows sub classes to control the turn of events.
There are many websites out there, where you can get examples for each of these types. But I have tried to keep this simple and straight forward. Just go through this to quickly revise what you need to know when it comes to patterns. It has main types and sub types and how they behave and function. That’s all you need to get through now!