0
What are practical use-cases of classes?
I am having trouble remembering class functionality because I cannot think of any practical use cases. I understand inheritance could be useful but I cannot think of a reason why its better than standard $var setting. Give an example of classes being absolutely necessary. (please)
1 Odpowiedź
+ 3
Classes are never absolutely necessary, but they can help making a long program easier to read/maintain and safer.
If you only use functions and define your values anywhere, you end up with long lists of functions and even longer lists of values. It can become hard to keep track of what relates to what.
Classes allow you to connect some data to only the related functions, which helps keeping stuff together that belongs together.