Java Design Patterns – Example Tutorial
Design Patters are a set of industry standard approach to a software problem. They are very popular among software developers.
Important uses and benefits of using design patterns are:
- Design Patterns make code re-usable and editable easily, since they are already defined ways to follow code writing and hence any new member can easily know what process the code is following easily.
- If used sensibly, it can lead to saving a lot of time as it provides a standard approach to solving a common problem.
- It also leads to creation of robust and highly maintainable code from all aspects.
Java Design Patterns are basically divided into three main categories . Creational, Structural and Behavioral design patterns. They are defined with examples below one by one.
- Creational Design Patterns
- Singleton Pattern
- Factory Pattern
- Structural Design Patterns
- Behavioral Design Patterns
Creational Design Patterns
Creational Design Patterns help to give solution to instantiate an object in the most possible best way in specific situations.
1. Singleton Pattern
A design pattern in which only one instance of class exists in the java virtual machine is defined as a Singleton Pattern. It restricts instantiation of the class hence making it appear only once at a time. Singleton Pattern does come with a lot of implementation concerns as there are many different approaches in its implementation. Checkout Java Singleton Pattern for examples.