Old Possum’s Practical Post on OOP (Object Oriented Programming)

Let’s talk about OOP, and we’ll use cats as our example:

Classes – we skipped this since the objects were built-in, but just know you can write classes to represent other objects. If you recalled biology, you learned about classification. You probably learned that cats (aka felines) are members of the animal kingdom. When we talk about a cat in general, we are referring to the cat class

Objects – objects are things (how’s that for a recovering English teacher?). Objects are specific things. Take Fluffy the cat for instance (Get it? For instance?). Fluffy is a cat, a particular cat. Any “thing” can be described in two ways: it’s traits or attributes (aka properties), and it’s actions (called methods in OOP)

Note: another term I did not introduce, but is almost always introduced with objects, is instances (remember ‘take Fluffy for instance’?). The word instance is pretty much interchangeable with objects. If you want to split hairs, you would use objects as a general term, and instance when you are specifically mentioning an object in particular. To carry the cat analogy even further, you might refer to all the cats running around your neighborhood as cat objects, and when you want to specifically refer to Fluffy, you would refer to her as the Fluffy instance.

Attributes or Properties – are variables associated with an object. Any given cat will all have the same general properties (all have fur, all have (or at least started out with) claws, all have legs). Please note:

  • Properties can have different values among different cats. Fluffy’s fur might be orange, and Morrisey’s fur might be black. The same thing goes for software objects.
  • Methods – are the behaviors of objects. For example, Fluffy, like all cats, meow, eat, like to chase things, etc. In OOP, objects have methods associated with them so that they can interact with other objects or the user.