Created
July 30, 2021 18:46
-
-
Save matthewoestreich/ba89bebeba5bee73e11e4c8b2ddbb81a to your computer and use it in GitHub Desktop.
House
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 House { | |
# Lower case bc private | |
hidden [Room[]]$rooms | |
# Constructor (PoSH support overloading, which is huge) | |
House() { | |
$this.rooms = Room[]; | |
} | |
# [Room[]] means our return type is an array of Rooms | |
[Room[]] GetRooms() { | |
return $this.rooms; | |
} | |
[void] AddRoom([Room]$room) { | |
$this.rooms.Add($room); | |
} | |
} | |
class Room { | |
[ValidateNotNullOrEmpty()][String]$Name | |
Room([String]$Name) { | |
$this.Name = $Name; | |
} | |
} | |
class Bathroom : Room { | |
[ValidateNotNullOrEmpty()][Boolean]$FullBath; | |
Bathroom([String]$Name, [Boolean]$isFullBath) { | |
$this.Name = $Name; | |
$this.FullBath = $isFullBath; | |
} | |
} | |
class Bedroom : Room { | |
[ValidateNotNullOrEmpty()][Int32]$SqFeet; | |
Bedroom([String]$Name, [Int32]$SqFeet) { | |
$this.Name = $Name; | |
$this.SqFeet = $SqFeet; | |
} | |
} | |
$myHouse = [House]::new(); | |
$bathroom = [Bathroom]::new('Master Bath', $true); | |
$guestBedroom = [Bedroom]::new('Upstairs Guest', 300); | |
$myHouse.AddRoom($bathroom); | |
$myHouse.AddRoom($guestBedroom); | |
Write-Host $myHouse.GetRooms(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment