The Strategy of the Backup Ritual
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Abjuration // Sysadmin Telepathy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// POWERSHELL PATTERN //
class IBackupStrategy {
[void] ExecuteBackup([string]$path) { throw "Not Implemented" }
}
class FullBackup : IBackupStrategy {
[void] ExecuteBackup([string]$path) {
Write-Host "Performing FULL backup on $path" -ForegroundColor Cyan
}
}
class IncrementalBackup : IBackupStrategy {
[void] ExecuteBackup([string]$path) {
Write-Host "Performing INCREMENTAL backup on $path" -ForegroundColor Yellow
}
}
class BackupJob {
[IBackupStrategy]$_strategy
BackupJob([IBackupStrategy]$strat) { $this._strategy = $strat }
[void] SetStrategy([IBackupStrategy]$strat) { $this._strategy = $strat }
[void] Run([string]$path) { $this._strategy.ExecuteBackup($path) }
}
# Deploying strategies
$job = [BackupJob]::new([FullBackup]::new())
$job.Run("C:\Data")
$job.SetStrategy([IncrementalBackup]::new())
$job.Run("C:\Data")
The Strategy pattern provides a grimoire of interchangeable backup algorithms. Depending on the moon phase or storage limits, the sysadmin swaps out the backup spell dynamically at runtime.
Runic Tags:
#powershell
#sysadmin
#behavioral
#strategy
#backups