PartyMember class inside the PartyManager.cs?

Hello there! I was just wondering if it wouldn’t be neater to create an own script for the PartyMember class instead of implementing it beneath the PartyManager class?

I always learned in coding that it is good to capsule code, especially classes, like that. Is there any particular reason that we do it in one cs-file?

Thank you! :slight_smile:

1 Like

Technically, having the class as a separate file or in the same file makes no difference. It is, however, best practice to have each class in it’s own file because it improves maintainability and readability. Unless, of course, the class is a nested class. It’s quite different to have nested classes in its own file, bringing in partial classes which is another concept that could take some getting used to.

2 Likes

As a rule of thumb, I tend to put all classes in their own files. Very rarely, I will leave a helper class in the same file if it’s generally only referenced within that class. Of course, in those cases I almost always enclose those helper classes within the class.

That does not mean that Andrew is in the wrong. It’s common during the prototyping phase as we build our classes from the ground up to keep associated non-MonoBehaviour classes with the MonoBehaviour that uses them. You can always move the class to another script at any time, or as you continue the course, you can move them to their own files as Andrew creates them. Just remember not to have them descend from MonoBehaviours or you won’t be able to use them.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms