When do I use new classes?
Hi, me again. Sorry for the post bombing. I'm an apprentice in programming and I'm wondering when to use another class in a script. I always want to structure my scripts and I'm wondering if this will help.
Answer by Matthewj866 · May 11, 2017 at 04:12 PM
If you mean in terms of OO theory, then I will direct you to the SOLID design principles
http://www.codeguru.com/columns/experts/solid-principles-in-c-an-overview.htm
Specifically, the single responsibility principle is probably the best judge for creating new classes. In essence, every class and method should have one responsibility. For example if we created a static class called Calculator
that class should not be responsible for anything other than providing mathematical functions such as add and subtract. If the Calculator
class is then responsible for also outputting the result to the screen, this would be considered a super class under this principle and create a new class for actually displaying the result would allow it to adhere to the principle again.
TL;DR - if your classes are doing stuff outside of their main purpose, then you need a new class.
Your answer
Follow this Question
Related Questions
(SOLVED) Accessing (string) arrays by enumerations from another class 0 Answers
How to create a drop down menu in editor inspector 0 Answers
How to override constructor when creating a new element in a list from the inspector. 0 Answers
Use a class like a function 1 Answer
How to get the component in a new class 0 Answers