PoshCode / PowerShellPracticeAndStyle

The Unofficial PowerShell Best Practices and Style Guide
https://poshcode.gitbooks.io/powershell-practice-and-style
Other
2.24k stars 289 forks source link

Style Guide for classes #97

Open tyteen4a03 opened 7 years ago

tyteen4a03 commented 7 years ago

It would be nice to have PS Style Guides for classes as well.

OCram85 commented 7 years ago

This post from @xainey really helped me understanding classes and develop an own style.

But I always struggle about things like this:

So maybe it's worth thinking about a style guid for the syntax and a best practice for the usage itself?

vexx32 commented 6 years ago

I think the only time where I would consider it a mandatory requirement to have a class is for input validation where you need a specific type of object with a specific set of properties. I would also include a constructor that can take any PsCustomObject provided it has the right properties (and would otherwise throw an error), as well as one that simply takes all necessary properties as input.

As for combining objects, I believe Join-Object is capable of this regardless. If you wanted this join to result in a different class, you could do the join in a constructor.