With never having worked with an object oriented programming language before starting the OO section of Ruby for Flatiron, it seemed foreign to me. Everything was unclear as to why this was different from other forms of programming until I worked through more of the curriculum and did some of my own research. Hopefully I can reiterate what I’ve learned in a succinct manner over these next few paragraphs.
“Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.”
– Wikipedia
It seems like that excerpt is saying that it’s just like other programming but with objects. Wow, what a surprise, object oriented programming deals with objects!
That really cleared things up…not!
To actually make things clear we can first ask ourselves, what is an object? In the real world we naturally think of things as objects. A person can be represented as an object since they have behaviors (methods) and attributes (data). An example of a person’s method would be to pick up groceries and an attribute would be their name.
“If you want to change the television channel from your seat, you use a remote control. That remote control is an object with a number of attributes and behaviors hidden inside of it. Without an understanding of those hidden attributes—the microchips, wiring, etc.—you still know and expect that pressing a button will perform that particular function.”
–Upwork
This is what we want to do with our code in a lot of situations. Focusing on interactivity, abstraction, and how the objects behave and not the “hidden” code that tells the objects how to behave. It makes for reusable components and simpler future modification. I’ll leave you with a quote about this from one of Flatiron’s Mass Assignment and Metaprogramming lessons.
“That is one major goal of design in object oriented programming––the writing of code that accommodates future change and doesn't require a lot of modification, even as it grows.”