Skip to content

Instantly share code, notes, and snippets.

@oze4
Created July 30, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oze4/ba89bebeba5bee73e11e4c8b2ddbb81a to your computer and use it in GitHub Desktop.
Save oze4/ba89bebeba5bee73e11e4c8b2ddbb81a to your computer and use it in GitHub Desktop.
House
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