diff --git a/src/main.ts b/src/main.ts index 0f19224..5ad1ba8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ export type CloudProvider = 'google' | 'azure' | 'aws' export interface VirtualMachine {} export interface Storage {} export interface Network {} +export interface Database {} export class AzureVirtualMachine implements VirtualMachine {} export class GoogleVirtualMachine implements VirtualMachine {} @@ -15,6 +16,10 @@ export class AzureNetwork implements Network {} export class GoogleNetwork implements Network {} export class AWSNetwork implements Network {} +export class AzureDatabase implements Database {} +export class GoogleDatabase implements Database {} +export class AWSDatabase implements Database {} + export class CloudProviderNotSupportException extends Error {} export class VirtualMachineNotSupportedException extends Error {} export class NetworkNotSupportedException extends Error {} diff --git a/src/singleton.test.ts b/src/singleton.test.ts new file mode 100644 index 0000000..315782c --- /dev/null +++ b/src/singleton.test.ts @@ -0,0 +1,10 @@ +import { describe, it, expect } from "bun:test"; +import { AzureDatabase } from "~/singleton"; + +describe("AzureDatabase", () => { + it("should create only one instance", () => { + const instance1 = AzureDatabase.create(); + const instance2 = AzureDatabase.create(); + expect(instance1).toBe(instance2); + }); +}); \ No newline at end of file diff --git a/src/singleton.ts b/src/singleton.ts new file mode 100644 index 0000000..f0d6b46 --- /dev/null +++ b/src/singleton.ts @@ -0,0 +1,16 @@ +import { Database } from "~/main" + + +export class AzureDatabase { + private static instance: Database + + private constructor() {} + + static create(): Database { + if (!AzureDatabase.instance) { + AzureDatabase.instance = new AzureDatabase() + } + + return AzureDatabase.instance + } +} \ No newline at end of file