Last active
July 30, 2024 13:53
-
-
Save dfinke/c76bbc6b90b537f03507a1e6b9ecebb4 to your computer and use it in GitHub Desktop.
PowerShell example demonstrating the Facade Design Pattern implementation
This file contains 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
class CPU { | |
freeze() { "$this freezing" | Out-Host } | |
jump($position) { "$this jump to $position" | Out-Host } | |
execute() { "$this execute" | Out-Host } | |
} | |
class Memory { | |
load($position, $data) { | |
"$this load $position $data" | Out-Host | |
} | |
} | |
class HardDrive { | |
[object] read($lba, $size) { | |
"$this read $lba $size" | Out-Host | |
return "(some data)" | |
} | |
} | |
# Façade | |
class Computer { | |
hidden [CPU]$cpu | |
hidden [Memory]$memory | |
hidden [HardDrive]$hardDrive | |
Computer() { | |
$this.cpu = New-Object CPU | |
$this.memory = New-Object Memory | |
$this.hardDrive = New-Object HardDrive | |
} | |
StartComputer() { | |
$this.cpu.freeze() | |
$this.memory.load(0, $this.hardDrive.read(0, 1024)) | |
$this.cpu.jump(10) | |
$this.cpu.execute() | |
} | |
} | |
$façade = [Computer]::new() | |
$façade.StartComputer() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment