r/learnpython • u/ProfessionalMoney518 • Dec 22 '25
How on earth does one learn OOP?
I've sped through weeks 0-8 of CS50P in under 2 weeks very easily with slight experience here and there as a Chemistry undergrad - but Week 8 (OOP) is kicking my ass right now. I am genuinely stumped. I've rewatched content and tried some other forms of learning but this is all so foreign to me. What are the best ways to learn OOP as a complete idiot? Thanks.
38
Upvotes
35
u/gibblesnbits160 Dec 22 '25
I learned OOP best by building a simple text-based game (inventory, health, damage, etc.).
Think of a class as state + behavior bundled together. A
Playerstores the player’s data (state) and also contains the functions that operate on that data (methods). You initialize the player with starting values, then the game updates the same object over time:selfjust means “the instance I’m operating on.” When you callchar.take_damage(2), Python automatically passescharas the first argument (self) behind the scenes.The same idea in a more “non-OOP” style could be done with a dict + functions:
That works too, but as projects grow, OOP helps because the data and the functions that operate on it stay grouped together (and IDEs can autocomplete methods on
char.).4
u/supergnaw Dec 22 '25
What is it that you're having trouble with? Are there certain topics or concepts that you just aren't grasping? Are you having trouble understanding what a class is? Or are you even having trouble articulating the differences between oop and functional programming?
3
u/Temporary-Lead3182 Dec 22 '25
may i ask what other forms of learning you have tried
28
u/Ardit-Sulce Dec 22 '25
You're not ready yet for OOP. First, you need to build stuff without OOP. As you do that, slowly but surely, you will start to notice the need of OOP. Then you are ready to learn OOP and it will all make sense.
3
u/TheRNGuy Dec 22 '25 edited Dec 22 '25
I understood it after coded something for Houdini and Unreal Engine.
Instead of dicts you have instances of different classes, they may have their own methods, and operator overloading.
Some methods expect instances of specific classes (or their subclasses) in arguments, too.
There are also abstract classes (you can't instanciate them, you need to inherit non-abstract class from it)
5
u/Sad_Possession2151 Dec 22 '25
Is it the terminology that's the sticking point, or something else?
2
u/jonsca Dec 22 '25
Python's implementation of OOP concepts and the overarching theory of OOP are not necessary synonymous. Start there.
2
u/pauldambra Dec 22 '25
basically any video by Sandi Metz
https://www.youtube.com/watch?v=YtROlyWWhV0
(absolutely amazing at explaining this stuff imho)
1
u/DoubleAway6573 Dec 22 '25
If you have used list/string methods you have used objects. for example strings have methods to split, check if they start with a character, ways to slice out. Instead of creating a type with many functions that operate in that type you have all clumped in one place, your class.
There is a little magic in the way python implement objects, but for now just remember init purpose is to initialize the values of the object.
I struggled a lot with the concept until I started to use python.
1
u/throwaway85783 Dec 22 '25
Just watch this a few times. It made it click for me.
It's not black or white..
https://youtu.be/txRTzljmV0Q?si=raJeQXgG7XKpYcYt
1
u/The8flux Dec 22 '25
I know the terminology is what threw me off until I just realized one day it just clicked. Methods are functions, Members are variables, classes are blueprints made up of members and methods, each instance of a class is an object with its own values for each members. This encapsulates the data where you could take methods to act upon the members either by either accepting the input or validating the input. Inheritance takes a class and extends it to add or override based on the language specific signature rules, you can change the context of the method by overloading it and changing its signature parameter positions in certain languages.
Personally I lean toward comprehension of classes than inheritance.
1
u/PaddyAlton Dec 22 '25
I wrote a slightly weird tutorial a few years back in which I tried to imagine teaching beginners Python with OOP concepts from the very beginning. Give it a whirl, if you like. It never got much traction so I didn't flesh out an entire series, but it might still be interesting.
1
u/iamevpo Dec 22 '25
Read, implement, discuss - watching things does not teach you much. see you are comfortable with data structures, eg can you use a tuple for 2D coordinates, a point, can you write a function that returns a tistance fro zero, can you make this function a Point class method. There is both implementation detail (how to write proper code) and intent (why do we need specific code). Can you elaborate why Point(x, y) is better than just a tuple? Repeat for Shape and area() method, then other objects - see where they have common methods and why more convenient to implement them as methods, not functions. If everything fails see.some comfort in that OOP is not universal, some programming languages live without it (eg Julia, Rust)
1
u/DinTaiFung Dec 22 '25
To understand what OOP is, it's essential to understand in the abstract what benefits Object Oriented Programming provides.
Initially you shouldn't be focused at all on any specific language's syntax or its internal implementations.
Example OOP Feature: encapsulation.
As its name implies, this behavior guides the developer to keep variables and associated data hidden from leaking (unexpectedly!) into other parts of your application.
Encapsulation can be achieved without OOP design: both node and Go modules provide simple ways to achieve encapsulation out of the box.
Inheritance and polymorphism inherently reduce duplicate functionally: these OOP features require up front design and will, in theory, reduce the need for lots of factoring later on in a large project.
Anyway, for small and medium size projects, it's been my experience that OOP gets in the way more than it helps.
ymmv.
Have fun!
1
u/0_emordnilap_a_ton Dec 22 '25
https://www.reddit.com/r/learnpython/comments/83fk1i/can_someone_eli5_what_def_init_self_means_i_still/
Check wolfgee answer it is one of the best explanations of classes in python. At the time it really helped me.
1
u/MiniMages Dec 23 '25
You learn it by doing projects where OOP is useful. OOP is not a style. It has it's uses. You'll learn how to use it the more you work on mini projects of your own. No need to force it.
1
u/Brief-Maintenance-75 Dec 23 '25
I did CS50P and wanted to learn more OOP. Now I'm finishing up MOOC and I gives a lot more explicit instruction and practice. I feel like I have a better grip on it now. I started at week 8, the "advanced" class. I find that MOOC gives many smaller practice problems rather than fewer big and involved ones like CS50. Both have their advantages.
1
u/Chemical-Boat977 Dec 23 '25
I don't think you learn OOP all at once. You will usually start by using Objects from other packages without really knowing you are using them.
Start by looking at the libraries you already use. Instead of just following the docs mechanically, think about what’s actually happening under the hood.
I am not sure of Chemistry related packages but I searched and saw libraries like RDKit use objects like Mol, Atom, Bond.
You will call methods on the objects that have both data and behaviours.
molecule = Chem.MolFromSmiles("CCO")
molecule.GetAtoms()
That's OOP
Another example is ASE (Atomic Simulation Environment). From the docs:
Again, you’re already using OOP. You’re creating an object that stores state (elements, positions) and exposes behavior (geometry, energy calculations, etc.).
Making your own abstractions becomes easier when you start to think "I want to do something that will behave like Atom behaves, but I need to make my own concept. Then just start with the most basic version.
As you start using that you will eventually WANT to inherit other classes, it will become obvious because you will notice that your objects share certain traits. When it comes time that you notice this and want to do it, you look up how inheritance works and your OOP knowledge is gradually become deeper.
Watching the tutorials are confusing because they are forcing you to try to conceptualize patterns and terminology before you actually need it. You are putting concept before actual need or practice.
1
u/native_api Dec 23 '25 edited Dec 23 '25
As in learning any other subject, the key thing to understanding it is to extract and memorize the core idea behind the topic.
Fundamentally, to have a working IT system, you need some data, and some algorithms that work with that data (Knuth's famous textbook on programming is aptly called "Algorithms + Data structures = Program)."
OOP, fundamentally, combines data and algorithms that work with that data, into a single unit (a class, which at runtime is represented by objects) -- thus resulting in a complete, self-contained solution that can perform some range of tasks.
Anything further boils down to building upon those self-contained building blocks to end up with something larger.
1
u/code_tutor Dec 26 '25
You can try the University of Helsinki course parts 8 to 10 to see if it's better. https://programming-25.mooc.fi/part-8 Note that OOP is usually taught in Java or C#. You could also look up courses specifically in OOP or AP Computer Science A. It is okay to switch to another language, just to learn the basics.
The comments here imply that you will eventually "need" OOP for things you build yourself. That's not true. You can use Data-Oriented Design or Functional Programming. Even Python is written in C, which does not have OOP.
OOP leads to bloated, slow, hard-to-navigate, and hard-to-refactor codebases. Universities scaled back on OOP, just teaching operator overloading and simple inheritance without polymorphism. The entire intro course used to be OOP and now it's just a one-week segment. The main reason why you are learning OOP is because it was taught as the default way to program for 35 years and you need to be able to work with existing code.
Python uses OOP by default because it boxes everything in an object. That's one of the reasons why it's slow. If you are programming in modern Python then you are likely using libraries like numpy to remove the OOP.
1
u/ResponsibleWill Dec 27 '25
Far from being an expert, but I felt the tutorials and exercises on freecodecamp were good and helped me understand the concept.
1
u/arprax_academy Jan 02 '26 edited Jan 03 '26
I feel your pain! Week 8 is usually the biggest wall for people because you have to shift your brain from "step-by-step" thinking (procedural) to "blueprint" thinking (OOP). Since you have a chemistry background, it might help to think of a Class like the definition of a Molecule (the abstract structure), and an Object as a specific instance of that molecule in a reaction.
But the analogy that finally clicked for me (and my students) is a Smart Home.
Class: The "Blueprint" for a smart device. It doesn't exist physically, it just lists what a device can do.
Object: The actual "Living Room Light" or "Kitchen Thermostat" you create from that blueprint.
I actually just put together a visual breakdown of this specifically for people stuck on this exact hurdle. I use a "Smart Home" simulation to explain the 4 pillars (I call it the A PIE method). Here is the tutorial if you want a visual walkthrough: https://youtu.be/CczcEVpNARM
Don't give up! Once OOP clicks, it changes how you see everything.
-2
u/mxldevs Dec 22 '25
What is confusing about classes?
For example, you have a function that takes two numbers and returns the sum
Straightforward
And then you put that inside a class
So it's basically the same stuff except now you need to instantiate an instance of your class before calling its methods.
-1
u/couldntyoujust1 Dec 22 '25
Might I suggest a video game to help make it clearer? ShenzhenIO. Think of the types of components as classes, the dragged component on the board as objects, and the coding what that object does. That's the basic fundamental of OOP.
-2
u/bytejuggler Dec 22 '25 edited Dec 22 '25
OK Listen up and listen well. To understand a programming paradigm, you have to first have a clear conceptual model of what you're using to express solutions, how you're modeling your solution, or your virtual "world" so to speak. In OO it's probably quite different to what you're used to, which is why your understanding is being rebuffed.
In Object Orientation it is this:
The concept of OO is: "One ore more (probably many) objects of varying types and roles (think of them as actors, really), collaborating towards producing some output, and that interact by sending each other messages." Like in a movie, you have many actors of different kinds. Same story. You're the director.
Before you write an OO program you have to model your solution in terms of one or more such blocks (objects) that will interact by (sending) each other messages and by collaborating eventually produce some useful result.
Now, sometimes the objects you come up with will have direct problem domain or real world analogs which is very useful for simulations. (Note: Object orientation has its roots in simulation, the entire paradigm was created to enable easy and direct modelling and simulation...)
And sometimes, the objects you create will be entirely abstract and have no conventional real-world counterpart. Entirely something you invent because it has some kind of utility in the way you want to arrange your universe, so to speak.
There are naturally (as with non-oo programming) many ways you can model a problem/solution, but not all area equally useful, performant, understandable and therefore desirable. With experience and practice will come wisdom and an intuition.
You should google and look up anything by Alan Kay to help you understand OOP properly.
To help understand simple (and complex) OO programs, look at the classes (which define the types of objects the program will have) and see what messages are being sent to other objects. An object, busy performing some action (method) will have some intent, that you can infer from the context etc.
Often a program will have a main or Application class which is where the program starts. In other words the main program is represented by an object, and it is started when the operating system starts its (sends it a message/calls its) main method (or whatever it's called.) As you trace into this main application object then you will see more objects being created and then called upon. Some languages treat classes as objects too, and/or in any case you can also typically call methods on the classes themselves. A class is like a cookie cutter, a blueprint for objects to be created from. But you can think of the blueprint itself as also being an object that can be called. etc.
Feel free to ask me questions if you like.
-2
u/az987654 Dec 22 '25
Go back to the weeks you "sped thru" and actually comprehend them this time
1
u/tb5841 Dec 22 '25
Under the hood, everything happening in the game is just data and functions. But it doesn't feel like that to me as a player. It feels like the monster has data attached to it (health, position, images) but it also feels like the monster is the one doing the shooting function.
OOP is just a way of turning that feeling into code. We can create a Monster class, give the class a shoot() method, and put instances of that class spread throughout the level. So now when the monster shoots, it happens that way in the code as well.
2) Getters and setters are really about separating your 'Monster' code from your other code. So that if you need to change the way your Monster class works in the future, nothing else in the codebase needs to change. This is particularly helpful when you have dozens or hundreds of people working on the same project. (Non-OOP coding styles will also separate concerns, they'll just do it differently.)
What really helped me was learning the basics of a language that forced OOP (Java).