This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Dat Mee
almost 9 years

Understanding Classes vs Objects vs Instances

This course is gliding by some really fundamental concepts in Object Oriented Programming (OOP) that students really need to understand in order to grok how classes work within the larger framework of how OPP works.

The truth is that object oriented programming often creates confusion by creating a disconnect between the philosophical side of development and the actual mechanical workings of the computer. I’ll try to contrast the two for you:

The basic concept of OOP is this: Class >> Object >> Instance.

The class = the blue print. The Object is an actual thing that is built based on the ‘blue print’ (like the house). An instance is a virtual copy (but not a real copy) of the object.

So when the course inexplicably and without much contextual definition says things like

The first argument init() gets is used to refer to the instance object,

It gets confusing because terminology is being mixed up and combined in unintuitive ways. It helps to think of it like this:

A blueprint for a house design is like a class description. All the houses built from that blueprint are objects of that class. A given house is an instance.

Finally, keeping in mind the following may help with grasping the concept:

The key difference between a function and a class method: A function is floating free, unencumbered. A class (instance) method has to be aware of it’s parent (and parent properties) so you need to pass the method a reference to the parent class (as self). It’s just one less implicit rule that you have to internalize before understanding OOP. Other languages choose syntactic sugar over semantic simplicity, python isn’t other languages.

Answer 55948fb476b8fea65a0006bd

0 votes

Permalink

Thank you, this is very helpful. I’m still going to have to do some research to really grasp that, but this is a great start.

points
Submitted by Paul W Peterson
over 8 years

Answer 55a2ddfbd3292f0ff40001e5

0 votes

Permalink

Thank you for that useful analogy!

points
Submitted by mixelpix
over 8 years