Today's food for thought is Object Oriented Programming (OOP). Actually, this will be an organized summary of some OOP concepts for reference (and slog requirement...) rather than any interesting ideas.
Before OOP came along, I thought about a program as a series of commands. Each command does something. I want to handle some repeating task... make a loop. I want to do something in certain cases... use an if statement. But at the end, these are all part of a command. Next, we link several commands into a new master command. We call this a function... Here, we realize that only certain data can be passed on and that these data may be linked together... why not create an object that binds all the data (attributes) together and the functions that operate on it (methods). Now, we have OOP. I made a previous post about usefulness of OOP describing mostly in the context of going from a function to objects.
So... in essence, objects are just containers. It is there for human beings to process what is going on more easily. I want to emphasize that objects are just there for human beings and our inability to track many things simultaneously. As an example, take 5 dogs. I spread around their names and colors and age etc all over the place. that's 15 variables. I can't remember which dog was what. Now let's link all those attributes into one thing- an object- a Dog! I can remember 5 things :) Now, the program remembers for me which dog has what attribute. It also remembers how they bark (see previous post), etc.
Only after understanding that OOP is a form of organization method to boost our productivity that we can talk about how to design them. I have provided my method for OOP design in a previous post with assignment 1 as an example.
In the next post to follow, I will discuss the components and more about how to think about OOP in a more theoretical way.
EDIT: Here and in most of my other posts on OOP, I only talk about the positive effects, but greying student has pointed out some pitfalls of OOP. What do you get when you subdivide your code too much? I think this idea is somewhat in line with the "human aspect" I talk about here, but anyhow, I thought it was interesting to point out.
No comments:
Post a Comment