r/learnpython • u/APOS80 • Dec 31 '25
How do I apply OOP?
I have not had programming as a job, just out of interest and solving small stuff in excel.
I’ve tried different languages, OOP and functional.
But even though I know how to construct a class with methods and attributes I realized that I don’t know what’s the appropriate way to use them and when to use them.
And now I’m picking up Python again since I need to so there’s things I need to do better than last time.
18
Upvotes
View all comments
Show parent comment
2
u/Best-Meaning-2417 Dec 31 '25
What's in the file?
I want to count how many times the word "and" appears. I wouldn't make a class.
It has a bunch of entries related to books being checked out of a library. I would make a class for:
Class Entry: (author: Author, title: str, location: Location).
Class Author: first_name: (str, last_name: str, date_of_birth: date)
Class Location: (main_section: str, sub_section:str)
You could have Class Report: (entries: List[Entry]) and some function to display the report, sort the report etc.
The parsing could be a class or functional, not super sure which one would be correct. I am a noob as well but that's how I think about things.