Created
May 30, 2024 19:48
-
-
Save dfinke/c56523901dff6b6bcc4d273bb69cd2ce to your computer and use it in GitHub Desktop.
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
class Command { | |
execute() { | |
"[$(get-date)] Logging execute of command [$this]" | Out-Host # Logs the execution of the command | |
} | |
} | |
class Loony : Command { | |
execute() { | |
([Command]$this).execute() # Calls the execute method of the base class (Command) | |
"You're a loony." | Out-Host # Outputs "You're a loony." | |
} | |
} | |
class NewBrain : Command { | |
execute() { | |
([Command]$this).execute() # Calls the execute method of the base class (Command) | |
"You might even need a new brain." | Out-Host # Outputs "You might even need a new brain." | |
} | |
} | |
class Afford : Command { | |
execute() { | |
([Command]$this).execute() # Calls the execute method of the base class (Command) | |
"I couldn't afford a whole new brain." | Out-Host # Outputs "I couldn't afford a whole new brain." | |
} | |
} | |
class Macro { | |
hidden [Command[]]$commands = @() # Defines an array property to store commands | |
add([Command]$command) { | |
$this.commands += $command # Adds a command to the commands array | |
} | |
run() { | |
$this.commands | ForEach-Object { $_.execute() } # Executes each command in the commands array | |
} | |
} | |
$macro = [Macro]::new() # Creates a new instance of the Macro class | |
$macro.add([Loony]::new()) # Adds a new instance of the Loony class to the macro | |
$macro.add([NewBrain]::new()) # Adds a new instance of the NewBrain class to the macro | |
$macro.add([Afford]::new()) # Adds a new instance of the Afford class to the macro | |
$macro.run() # Runs the macro, executing all the commands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[05/30/2024 15:48:06] Logging execute of command [Loony]
You're a loony.
[05/30/2024 15:48:06] Logging execute of command [NewBrain]
You might even need a new brain.
[05/30/2024 15:48:06] Logging execute of command [Afford]
I couldn't afford a whole new brain.