Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Guide for classes #97

Open
tyteen4a03 opened this issue Sep 14, 2017 · 2 comments
Open

Style Guide for classes #97

tyteen4a03 opened this issue Sep 14, 2017 · 2 comments

Comments

@tyteen4a03
Copy link

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

@OCram85
Copy link

OCram85 commented Nov 23, 2017

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

But I always struggle about things like this:

  • Is there a best case scenario when to define classes instead of creating PSCustomObjects and giving them a individual type name?
  • How complex should the class get? - How many different constructors do I need.
  • Should I use a class for combining different bbjects without any methods?

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

@vexx32
Copy link
Contributor

vexx32 commented Apr 20, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants