Design patterns
Design patterns are time-tested solutions to common software problems. They can be considered a set of best practices and are widely used for Java development. Concerning strategic object creation and immutability, two design patterns deserve our attention:
- Singleton pattern
- Factory pattern
What a design pattern is not
Design patterns are structured approaches to solving known problems. They are not algorithms, templates, libraries, or even code snippets. Instead, they offer high-level guidance that we can follow.
Let’s look at each of these patterns so that we understand how their use can help improve the performance of our Java applications.
Singleton pattern
The singleton design pattern ensures that there is only one instance of a class and then provides global access to that instance. This pattern is often used when an application is managing database connections, resource management, logging, caching, or configuration settings...