I have few queries on basic Object Oriented programming concepts.
I have done proper home work. I searched in net. but I am not satisfied with the answers i got. So I am posting this query?
In many places I have seen. this concepts means 1) Inheritance 2) Polymorphism 3) Encapsulation
then what abt abstraction???
a) What are the the actu properties? b) Its only the first 3 or it also includes abstraction?? c) Also I read some where abstraction means hiding implementation? is this true? if so where are we hiding the implementation exactly. even in a pure abstract class we dont have any implementations. Please explain me with proper example? d)Why people try to differentiate abstratcion and encapsulation? as both are different topics. as i know no where they are related. please explain with some real time example.
A lot of big questions, actually. I shall try to answer a few.
The real idea behind object-oriented (OO) programming is that you create software "objects" which have data (called fields in Java) and behaviour (called methods in Java). You can have a few objects or you can have as many as you can fit onto your computer's memory (I once tried and go to 6000000, but I didn't examine them individually!) Objects can communicate with one another; they send "messages" which tell other objects to do something. In Java we call those messages method invocations.
A class represents an abstraction; a Car class might have speed and colour, but you can't tell what colour the Car class is, nor what speed it is travelling at. [This is different from an abstract class; forget abstract classes for the moment.] An object is also called an instance of its class; you can have a Car object which records it is "red" and travelling at 60mph.
The class encapsulates all that, colour, speed, going faster, stopping, etc. It includes code to do all those things. It is a good idea to keep the data hidden so other objects can only reach them via methods, and to hide the way things are worked out (data hiding).
I hope that helps as a start, and I hope other people will have their own answers to add.
Also I read some where abstraction means hiding implementation? is this true? if so where are we hiding the implementation exactly.
As another example of this, let's say I have a FinancialApplication class that uses a method double(int x) from a Calculator class from another package or another API. How that method doubles the number is hidden from me. The FinancialApplication class doesn't know (or care) if it is doing x + x or x * 2. It's hidden.
Why people try to differentiate abstraction and encapsulation? as both are different topics. as i know no where they are related. please explain with some real time example.
When I think of abstraction, I like to use the Car analogy also. Not a car class, but an actual automobile. I'm no mechanic. I know very little about how a car runs under the hood. I do know how to get unlock a car door, get in, start the car, and control the speed and direction of the car with the accelerator, brake, steering wheel, gear shift, and clutch. Information hiding has a lot to do with it, I don't have to worry about pistons firing and crankshafts and the like, I know the harder i press on the accelerator, the faster I'll go. If I turn the wheel right, the car will veer right.
I can get into a rental car I've never driven before and be confident that I'll be able to navigate it to my destination. The abstraction of a car helps me in two ways to accomplish this. First off, by hiding all the gory details of the car's operation, I can worry about the important stuff like not hitting the other cars, and stopping a all the red lights. Secondly, since all car manufacturers have settled on a pretty consistent abstraction for operating a car, I know where the steering wheel is and what it does, and how to put the car in reverse even in a car I'm just driving for the first time.
If all manufacturers had a different operating abstraction, say if you accelerated with hand levers and steered with your feet in a BMW, and you could steer a Ford by leaning left/right and go faster by wiggling a joystick, then the common abstraction is lost. There are still abstractions there, but without a standard they make each driving experience unique.
I hope in all my rambling you may have picked up some little nugget of information.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
You know it is dark times when the trees riot. I think this tiny ad is their leader: