Ask your own question, for FREE!
Computer Science 22 Online
OpenStudy (anonymous):

tell me about object oriented!

OpenStudy (anonymous):

Good question; I was always waiting for some OO guru to show me the light of polymorphism, the difference between virtual and abstract methods, etc.

OpenStudy (anonymous):

i still waiting!

OpenStudy (anonymous):

All I know about OO programming is that it is a powerful means of abstraction, and that I am doing it wrong :(

OpenStudy (anonymous):

thank u!

OpenStudy (jagatuba):

The topic of OOP is very broad (and that's an understatement). Can we perhaps narrow the discussion to a more singular topic under the OO-umbrella?

OpenStudy (jagatuba):

And agdg, you've been doing pretty well from what I have seen.

OpenStudy (anonymous):

Read this http://en.wikipedia.org/wiki/Object_oriented_programming and tell us what you want to know precisely.

OpenStudy (anonymous):

Practically, object oriented programming allows you primarily to collect data and functionality to operate on that data in one place, and govern access to that data and functionality. For example, without any sort of object, your data would have to be held in variables that are either global or passed from function to function as parameters, and you would have much more freedom to shoot yourself in the foot in terms of validation of that data. OO makes it possible to describe your data, the relationships between them, and the operations on those data in a very intuitive way. A grossly simplified example: I could implement a bicycle in C by holding its wheel size, its chain length, the number of gears, and the current gear, the number of teeth on each sprocket, etc., all in global variables. The I could have to functions Cycle and Brake, that I pass in all the data (possibly dozens of variables) to, in order to modify a global variable speed. This may even work fine with one bicycle, but what If I wanted to simulate a dozen bicycles? The variables would turn into arrays, and I'd have to make sure to access all arrays with the same index. In C++, I'd create a class bicycle that holds the parameters of the bicycle in member variables (has-a relationship), and has two member functions Cycle and Break. I could then instantiate any number of bicycles, setting their parameters once in the object, and call Cycle() and Brake() without needing to retrieve all the parameters necessary for the functions every time I wanted to call one of these functions. That's only one aspect. Another important one of OO is inheritance. I could now create a class Tandem that derives from Bicycle and implements the data and functionality for a second seat and set of pedals, without needing to replicate the parameters of the wheel, first set of pedals, chain, etc. all manually. It's an is-a relationship: the Tandem is a bicycle simply by deriving from it. In that way, if I designed my Bicycle class well enough, I could implement all manner of bicycles - three-wheeled ones, motorized bicycles, bicycles with mirrors that are checked by the Turn() before turning, and so on - all without needlessly duplicating the code and data for the very basic bicycle, whose properties all derivatives share. This sort of thinking makes a huge difference especially in large code bases. When you're handling data for hundreds of thousands of objects in a million lines of code, it quickly gets unmanageable without some form of OOD/OOP. Imagine in the above (admittedly contrived) example, needing to create and manage three- or fourhundred different types of bicycles, each with different dynamics and functionality by just holding their data in global arrays or passing pointers to the data between functions, and you see what I mean. That was way wordier than I intended, but I hope it gets the point across :)

OpenStudy (anonymous):

The Big Picture! Very well organized explanation and example. Thank You @opiesche

OpenStudy (anonymous):

thank u every body.

OpenStudy (anonymous):

i dont know, you tell me!!! ;)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!