# bh5k/javase17creationaldesignpatterns architecture

> Architecture diagram of the GitHub repository bh5k/javase17creationaldesignpatterns, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bh5k/javase17creationaldesignpatterns
- Repository: https://github.com/bh5k/javase17creationaldesignpatterns

## Overview

This small Java example demonstrates two singleton patterns: a lazily initialized database singleton that supplies a JDBC connection, and Java’s built-in Runtime singleton. The database demo uses the connection to create a table and insert a row; the everyday demo compares two Runtime references. The database behavior is visible in the sampled source; no README describes additional capabilities.

Main entry points: [`src/main/java/com/pluralsight/singleton/DbSingletonDemo.java`](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingletonDemo.java) (Database Demo), [`src/main/java/com/pluralsight/singleton/DbSingleton.java`](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingleton.java) (Database Singleton), [`src/main/java/com/pluralsight/singleton/SingletonEverydayDemo.java`](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/SingletonEverydayDemo.java) (Runtime Demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_db_demo["Database Demo"]
node_db_singleton["Database Singleton<br/>[DbSingleton.java]"]
node_h2_db[("H2 In-Memory DB")]
node_runtime_demo["Runtime Demo"]
node_java_runtime["Java Runtime"]

node_db_demo -->|"gets instance"| node_db_singleton
node_db_singleton -->|"returns instance"| node_db_demo
node_db_demo -->|"gets connection"| node_db_singleton
node_db_singleton -->|"opens connection"| node_h2_db
node_db_demo -->|"executes SQL"| node_h2_db
node_runtime_demo -->|"gets singleton"| node_java_runtime
node_runtime_demo -->|"requests garbage collection"| node_java_runtime

click node_db_demo "https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingletonDemo.java"
click node_db_singleton "https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingleton.java"
click node_runtime_demo "https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/SingletonEverydayDemo.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_db_demo,node_db_singleton,node_h2_db toneAmber
class node_runtime_demo toneTeal
class node_java_runtime toneIndigo
```

## Components

### Other components

- [Database Demo](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingletonDemo.java): `src/main/java/com/pluralsight/singleton/DbSingletonDemo.java`
- [Database Singleton](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/DbSingleton.java): `src/main/java/com/pluralsight/singleton/DbSingleton.java`
- **H2 In-Memory DB**
- [Runtime Demo](https://github.com/bh5k/javase17creationaldesignpatterns/blob/m2-final/src/main/java/com/pluralsight/singleton/SingletonEverydayDemo.java): `src/main/java/com/pluralsight/singleton/SingletonEverydayDemo.java`
- **Java Runtime**

## Connections

- Database Demo → Database Singleton: gets instance
- Database Singleton → Database Demo: returns instance
- Database Demo → Database Singleton: gets connection
- Database Singleton → H2 In-Memory DB: opens connection
- Database Demo → H2 In-Memory DB: executes SQL
- Runtime Demo → Java Runtime: gets singleton
- Runtime Demo → Java Runtime: requests garbage collection
