-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBase.ps1
More file actions
75 lines (64 loc) · 1.46 KB
/
Base.ps1
File metadata and controls
75 lines (64 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.111
Created on: 2/23/2016 1:33 PM
Created by: June Blender
Organization: SAPIEN Technologies, Inc
Filename:
===========================================================================
.DESCRIPTION
This script shows how to use the Base keyword in the constructor of a subclass
to call a constructor of a base class.
#>
class Glass
{
# Properties
[int32]$Size
[int32]$CurrentAmount
# Constructors
Glass () { }
Glass ($Size, $Amount)
{
$this.Size = $Size
$this.CurrentAmount = $Amount
}
# Methods
[Boolean] Fill ([int32]$volume)
{
if ($this.currentAmount + $volume -le $this.Size)
{
$this.CurrentAmount += $volume
return $true
}
else
{
Write-Warning "Sorry. The glass isn't big enough. You have room for $($this.Size - $this.CurrentAmount)."
return $false
}
}
[Boolean] Drink ([int32]$amount)
{
if ($this.CurrentAmount - $amount -ge 0)
{
$this.CurrentAmount -= $amount
return $true
}
elseif ($this.CurrentAmount -eq 0)
{
Write-Warning "Glass is empty. Time to refill."
return $false
}
else
{
Write-Warning "Not enough left. Only $($this.CurrentAmount)..."
return $false
}
}
}
class AnyGlass: Glass
{
AnyGlass () {}
AnyGlass ($Size, $Amount): base($Size, $Amount) { }
AnyGlass ($Size): base($Size, $Size) { }
}