-
-
Save ronascentes/36aab80a823cf930db428157ccb0d22d to your computer and use it in GitHub Desktop.
PowerShell Singleton Pattern: Ensure single instance for shared resource management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Singleton | |
class Product { | |
$Name | |
Product($name) { | |
$this.Name = $name | |
} | |
} | |
class Creator { | |
static [Product]$product | |
static [Product] GetProduct() { | |
if ($null -eq [Creator]::product) { | |
[Creator]::product = [Product]::new((Get-Date)) | |
} | |
return [Creator]::product | |
} | |
} | |
$p = [Creator]::GetProduct() | |
$p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment