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
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.
Hoping for a quick response.
Thanks in anticipation.
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.
Mr Google has a lot to say on this subject, including this JavaRanch post.
As a side note, please UseRealWords when posting. Thanks.
[ July 10, 2008: Message edited by: Mark Vedder ]
Thanks for the immediate response.
I am just confirming my understanding. Please correct me if I am wrong.
1) If we are talking about OOPs principle means, we should speak about all the four principles, i.e including abstraction also.
2) This concept of abstraction is no where related to abstract class or interface. When I am talking about abstraction means its different from abstract class.
3) In Java, Classes use the concept of abstraction, by defining a list of attributes and methods that operate on these attributes.
Please correct me regarding these points.
I have few more points to discuss once these are confirmed.
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.