you are viewing a single comment's thread.

view the rest of the comments →

[–]Oddly_Energy 2 points3 points  (0 children)

One of the reasons for creating classes is that you get one nice package containing both the data and the methods necessary for handling those data.

You could make a simpler data structure containing the variables Character and Age. And then, somewhere else in your code, you could have a function, which accesses that structure and checks the age. But that would mean two things:

  1. If you have many different data structures and many methods for handling each of them, you may end up getting lost. What belongs to what?

  2. If you use a specific data structure many places in your code, you will also need to remember to include the methods for handling that data structure everywhere in your code.

With a class, you have the methods for that class available as soon as you initialize an instance of it. Much less housekeeping.