Intro
Design Patterns for Humans 🤗
Design Patterns are guidelines to recurring problems; guidelines on how to solve certain problems They are not classes, packages, or libraries that you can plug into an application and wait for magic to happen. These are rather guideline son how to solve certain problems in certain situations.
Design Patterns are guidelines to solving certain recurring problems.
Wikipedia describes them as:
In software engineering, a software design pattern is a general reusable solution to a commonly recurring problem within a given context in software design. It is not a finished design that can be directly ported into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations.
🚨 Be Careful!!
Developers, mostly beginners, makes the mistake of over-thinking and forcing the design patterns which results in un-maintainable mess. The rule should always be to make the codebase as simple as possible. Once you start developing you will start to see recurring patterns in your codebase, at which point you can start factoring your code using relevant design patterns.
- Design Patterns are not silver bullets to your problems. Use them consciously.
- Don't try to force them. Bad things might happen if done so!!
- Remember! Design Patterns are gudelines towards finding solutions to problem; not solutions to problems themselves.
Types of Design Patterns
Adapted from the Gang-of-four (GoF) book on Design Patterns
;
there are broadly three types of useful & popular design patterns:
- Creational
- Structural
- Behavioral
Creational Design Patterns
In simple words, Creational design patterns are focused towards how to instantiate an object or group of objects
Wikipedia says:
In software engineering, Creational design patterns are design patterns that deal with object creation mechanism; trying to create objects in a manners suitable for the sitation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patetrns solve this problem by controlling this object creation.
There are 6 types of Creational patterns:
- Simple Factory
- Factory Method
- Abstract Factory
- Builder
- Prototpe
- Singleton