After graduating from the limited sensorimotor stage of one's infancy, the human brain is capable of understanding that there exist instances of things in our life, such as people places and things which are unique and not nessecarily limited to the ones we can currently see, feel or hear. Object-Oriented Programming is, in my understanding, object permanence (knowing something can exist with or without it being currently in play) for the coding process. Consider an example challenge:
We'd like a write a program about pens. Perhaps for organizing types of pens. We know that not all pens are the same. How will we be able to work with pens, telling them apart from each other, easily representing what they are? OOP helps.
We know pens have different colours, and we can organize characteristics like this one in an Object. This makes sense of course. Pens are, in fact, objects. But just like in real-life: it's quite handy to have a basic idea of what a pen is in order to avoid confusion.
![]() |
| Are quills pens? Depending on the design of your program, quite possibly. Confused? |
So! We've decided pens are something important enough that our program will deal with them as instances of a Pen object. Listing off colour as a characteristic of interest, we write code that allows us to create pen objects with strings representing names and colours. Our lives just got a whole lot easier. Why?
Because we can now more easily manipulate the idea of pens in our code, write code that allows us to compare them, which then allows us to more easily organize them. Wait, wasn't that what we were trying to do at the start?
"We'd like a write a program about pens. Perhaps for organizing types of pens." -Adventures in SLOGing 2015
Well, there we go. Just by doing a few simple steps we've created a sensical basis for our program, and that's good in more ways than one.
Because we've written up Pens as an object and attentively commented our code (obviously) it's far easier for an outside party to view and understand what we've written, as well as modify individual parts of the code without as great a risk of messing things up. Presto: versatile, understandable, and effective code.
I struggle to come up with a complex problem that wouldn't benefit from code written in an Object Oriented design, but realize I am only starting out on the learning process.
Until next week, cheers!
- ES


No comments:
Post a Comment