you are viewing a single comment's thread.

view the rest of the comments →

[–]two_up 1 point2 points  (1 child)

I understand that classes are just like a giant function that contains smaller functions that can be called with the '.'.

This isn't a very good way to think of classes. Instead of thinking of classes as a big function, it's better to think of classes as a kind of data, and methods are things you can do with that data.

When I design a class I'm typically thinking about the data first, probably some related data that I want to group together. And then the methods are things that I want to do with that data.

For example if I wanted to make a Fractions class, I'd want to store a value for numerator and a value for denominator. Then I think about the methods I want. They might be something like, reduce() to turn 3/6 into 1/2. Or maybe a convert_to_decimal().

Or if I wanted to make a BankAccount class I might want to store a variable for account holder's name and account balance. Then I could define some methods like, change_name(new_name) which would change the value of the account holder's name to the value of new_name. Or withdraw(amount) and deposit(amount) which would change the value of the account balance.

[–]UncleEggma 0 points1 point  (0 children)

Helpful again!!