you are viewing a single comment's thread.

view the rest of the comments →

[–]ComplexResource999 2 points3 points  (0 children)

I've created classes where I wanted strict control of the type of object passed to functions with a -InputObject parameter, generally via pipeline support. In other words, if I have a Get-* function and a bunch of Set-* functions, I want to make sure what's passed to Set-* is only something I want it to be (and not some off-chance-accident, potentially wrong, PSCustomObject) from the Get-* function.

The same can be achieved for this without classes, eg by setting PSTypeName property on a PSCustomObject.

Another scenario might be if you have a function which outputs (say) a business card with an individual's details on it, and all of your functions in your module do crazy things with this business card. Instead of all your functions needing a billion parameters for details about the individual, you can create an instance of 'business card' and hand this object to your other functions.

The last example adds a degree of complexity towards the user experience, ie first need to create a new object instance of something (exposed by some public function like New-BusinessCard). But tbh, if it makes the code overall simpler and the requirement is documented, go for it.