Software design patterns
Software design patterns describe solutions to specific issues in software. This concept comes from architecture and engineering. Imagine that you need to design a bridge to cross a river. You will likely begin by choosing the bridge type or pattern. There are seven types of bridges:
- Arch bridge
- Beam bridge
- Cantilever bridge
- Suspension bridge
- Cable-stayed bridge
- Tied-arch bridge
- Truss bridge
These types, or patterns, describe how the bridge should span the river you wish to build your bridge over, but they do not provide detailed instructions or blueprints. They guide the architect in the design of the bridge. Software patterns work in a similar fashion. Let us look at four widely used patterns and how they could be implemented in Java.
Singleton
A singleton is a Java object that can only be instantiated once. It is a creational pattern. Wherever this object is used in an application, it is always the same object...