Exploring other design patterns
In previous chapters, we applied some design patterns while developing the topology and inventory system. These patterns helped us arrange code to support application needs better. So, in this section, we will review the design patterns we applied while implementing hexagonal architecture.
Singleton
Before introducing Quarkus to our topology and inventory system, we had to provide our own mechanism to create a single database connection object. When handling database-based connections, it’s common to have just one instance that connects to a database and shares that connection with other objects.
Singleton is the pattern we used to create a single database connection instance, as shown in the following example:
public class RouterNetworkH2Adapter implements RouterNet workOutputPort { private static RouterNetworkH2Adapter instance; @PersistenceContext ...