Q:

Design Pattern for returning Connection Object

We are working on PAAS applications (Spring Boot) which have 2-3 different modules in which each module has some redundant code for creating and closing database and MQ connections.
We are using Hikari DataSource for maintaining pool connections, and are planning to centralize the code which contains configuration data, putting that as a parent dependency in others.
Is there any suitable java design pattern which fulfills this use case?

A:

Probably either Factory Design Pattern or Abstract factory design pattern; They are conceptually almost same. UML diagram of it Factory Design Pattern
The Abstract Factory Design Pattern sounds fancier, but isn't anything more complex than the Factory Design Pattern. Abstract Factory Design Pattern.

