I tested and came across the following:
You can overload methods in PoShv5 as you wish. If you call a method with no parameters, it can internally call a method with parameters so that your code is not redundant. I expected this to be true for designers as well.
In this example, the last constructor works as expected. Other constructors return objects with no given values.
Class car {
[string]$make
[string]$model
[int]$Speed
[int]$Year
speedUp (){
$this.speedUp(5)
}
speedUp ([int]$velocity){
$this.speed += $velocity
}
car () {
[car]::new('mall', $Null, $null)
}
car ([string]$make, [string]$model) {
[car]::new($make, $model, 2017)
}
car ([string]$make, [string]$model, [int]$Year) {
$this.make = $make
$this.model = $model
$this.Year = $year
}
}
[car]::new()
[car]::new('Make', 'Nice model')
[car]::new( 'make', 'nice model', 2017)
Is there any way to fix this? Did I miss something?
source
share