
Design Patterns in Java
A design pattern is a reusable generic solution to a frequent problem in software design. Design patterns are recommended practices that experienced developers employ to overcome common challenges.
Knowing merely principles such as inheritance, polymorphism, and encapsulation will not qualify you as an excellent object oriented developer. You must consider developing reusable, adaptable, and simple-to-maintain systems. To handle certain common design difficulties, you need be familiar with at least a few design patterns.
Types of Design Patterns
Design patterns can be broadly classified in three categories: Creational, Structural and Behavioral design patterns.
- Creational Patterns : These design patterns deal with the problem of creating object while hiding the logic and complexity associated with it. Singleton Pattern, Factory Pattern, Builder Pattern etc comes under creational design patterns.
- Structural Patterns : These design patterns are used to define relationship between classes, objects and various entities. Adapter Pattern, Bridge Pattern, Proxy Pattern etc comes under structural design patterns.
- Behavioral Patterns : These design patterns deal with communication between objects. Command Pattern, Mediator Pattern, Observer Pattern, Strategy Pattern etc comes under behavioral patterns.























Principles of Design Patterns
- Identify the components of your system that varies and keep them separate from what remains the same. In this way, you can change or extend the components that vary independently without affecting the components that remains same.
- Program to an interface not an implementation.
- Favour composition over inheritance. In other words, a "HAS-A relationship is better than IS-A".
Advantages of Design Patterns
- Design Patterns helps you to build reusable systems with good object oriented design qualities.
- They capture the proven object oriented experiences. You don't have to re-invent again.
- It provides shared vocabularies that allows you to say more with less. It helps developers to communicate efficiently.
- Design patterns let you write better code more quickly.
- It specifies the best practices and solutions used the developers everywhere to solve a particular problems faced during software development.
- Patterns are not invented, they are discovered over time by experienced developers.
- Design pattern won't give you code or guarantee an absolute solution. It is a general solution of a commonly occurring problem that can be used in many different situations.
- Standard Libraries and frameworks are not design patterns. They are the implementations of design patterns.
- Most design patterns helps us to extend and vary components of a system independently of each other.