What are Design patterns?
According to Wikipedia, a software design pattern is a general, reusable solution to a commonly occurring problem
within a given context in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code.
Why Design Patterns ?
In short, they are used so that developers do not need to reinvent the wheel.
Detailed answer - While programming, you might come across some code design problems which occur frequently. Some of
these problems already have a well-defined solution which is generally more flexible, modular & abstract.
Advantages of Design Patterns:
- Design patterns make your lives easy as a programmer as these make possible you to get benefit from the experience and knowledge of your predecessors those have worked on the same type of project .Thus make it easy for further development of the applications.
- Appropriate design patterns used in development of applications make development fast and easily documented.
- The benefit of design patterns lies in reusability and extensibility of the already developed applications.
- Design patterns make your lives easy as a programmer as these make possible you to get benefit from the experience.
- Design patterns are more sophisticated and advance approaches than basic data structures such as arrays, linked lists, and binary trees.
- All design patterns use self-descriptive naming conventions and a design pattern based name of program objects captures a basic idea about the working and use of that particular object.
Disadvantages of Design Patterns:
- There is a learning curve required.
- The overall software development process has to be modified to take design patterns into account. So, integrating patterns into a software development process is a human-intensive activity.
- Not guaranteed to solve all the problems.
Things to remember
- Note that patterns do not magically improve the quality of your code.
- Excessive use leads to over-engineering.
I will quote an answer on a StackOverflow question on "When to use and when not to use design patterns" Always follow KISS first, patterns later, maybe much later. A pattern is a state of mind, mostly. Don't ever try to force your code into a specific pattern, rather notice which patterns start to crystalize out of your code and help them along a bit. Deciding "ok, I'm going to write a program that does X using pattern Y" is a recipe for disaster. It might work for hello-world class programs fit for demonstrating the code constructs for patterns, but not much more.