• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

what is Abstraction

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a JAVA beginner, please explain Abstraction in a bit detail.
I looked in a lot of books, but could not get a practical explanation.
Everywhere it has been said that it implies reduction in complexity and to hide details and expose whatever is really necessary.
Please explain it in a bit detail. Also tell me how abstraction is achieved in JAVA.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to represent a bunch of similar things that are just a little different, you 'abstract out' the common features. For example, if you want to make an application that tracks all the people at a school, you have students, teachers, administrators, custodians, etc. Each and every one will have a name, address, birthday, and so forth. Some will have salaries, some won't.

you can make an abstract class called "Person", and stick the common stuff there. you can make a string to hold the name, methods to set and return the name, and a method to print the name, since EVERYONE will need this.

Then you make more specialized classes for the specific roles - a Student class, a Teacher class, etc. each of these would then be derived from the abstract "person" class.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also take a look at this recent JavaRanch Tread on the subject; it has some examples. Also there is this a Wikipedia article on Abstraction that might help.
[ August 20, 2008: Message edited by: Mark Vedder ]
 
Vishal Vohra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks fred and Mark for your replies.

Fred,

Your post brings out the concept of Abstract Classes, does the concept of abstraction related to Abstract classes.

Mark,

According to the article on Wikipedia, Abstraction means -
"In computer science, abstraction is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time.

The following English definition of abstraction helps to understand how this term applies to Computer Science, IT and Objects - i.e. abstraction is:

A concept or idea not associated with any specific instance"

As the first part of the definition details about "reducing and factoring about details" - how is this achieved in JAVA.

Secondly, according to the second part of the definition does Abstraction means defining classes.

I found these definitions almost everywhere, so does abstraction really mean hiding implementation details and if it does, then does it also brings out the concept of interfaces and abstract classes which only provides method signatures and hide out the actual implementation from the end user.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract classes are one way of using abstraction, but not the only way. you could have a concrete parent class, for example. different languages all do it slightly differently.
 
Marshal
Posts: 78438
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred's first post is probably the most useful.


"What colour is a car?"

You can have "car" which has features like make, numberplate, colour, speed, engine size, etc etc.

That was an abstraction.

This is the concrete instance (not a real example).EVery car has make, colour, etc., but you will never find another red Focus 1.6 NT08 CRC doing 42 mph.
 
Vishal Vohra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred,

as you said "abstract classes are one way of using abstraction, but not the only way", please tell me what are the other possible ways of using abtraction.
I mean I just want to know, to what all concepts can abstraction lead to in JAVA (for example it leads to a concept of abstract classes in JAVA).

Campbell,

do you mean, that "representing a bunch of similar things with the help of classes" is abstraction.
 
Campbell Ritchie
Marshal
Posts: 78438
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but another way to look at it is "using classes to represent the common features of similar things."
 
Vishal Vohra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

As I posted earlier, in every textbook and on internet, it is written that to reduce complexity is abstraction.
How does "using classes to represent the common features of similar things", helps in reducing complexity?
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are probably as many different ways of using abstraction as there are people who write code.

personally, i always find the phrase 'reduces complexity' somewhat misleading. while it makes some things less complex, it makes other MORE complex.

one way it helps is that you don't have to keep re-inventing the wheel. You are added to a project that has been around for years, that models a bunch of cars (to continue with Campbell's example). you are told to write the code for a brand new car.

since much of the work is done - all the stuff common to all cars - you only need to focus on what's special about your car. you don't have to code for setting the color, or the engine size, or whatever. you only need to worry about what makes YOUR car class different than anybody else's.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstraction means : Show Functionality , Hide Complexity
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vishal Vohra:

As the first part of the definition details about "reducing and factoring about details" - how is this achieved in JAVA.



Take a look at this code:

In that code, Java has totally abstracted the file system from me. I can very easily determine if a file exists. Without Java's abstraction, I would need to know how to do that on every possible OS that Java runs on. Then in turn the OS' I/O functions abstract me (and Java) from knowing how to communicate with the different I/O drivers (CD ROM. tape drive, hard disk, USB memory stick, etc). The hard disk driver then abstracts the file access. The OS (and I) doesn't need to know how to send the right electrical signal to the hard drive to tell it to start spinning. Oh, and that varies for every possible hard drive models on the market (thousands of them). Then what electrical signal to send to move the drive head. Then what signal to send to find the file in question. etc, etc.

Each layer (Java --> JRE --> OS --> Motherboard Bus--> Hard Disk Drivers --> disk drive --> magnetic charges on drive patter) abstracts the complexity from the next layer. And in the end, in one simple line of code I can determine if a File exists. Thanks to Java's File abstraction, I don't need to know about the specifics of hard drives.

This is just one example of abstraction; more specific to the idea of reduced complexity and removal of details.

Even the "File object" or the term "File" is a type of abstraction. An electronic device (i.e. the hard drive) does not have manila folders on it. It doesn't have pieces of paper. It just has magnetically charged particles. We refer to a group of those particles that are related and represent last month's accounting report as "a file". That's an abstraction.

I think the car example in Garrett's reply in the thread I referenced above is a good example/explanation of this concept as well.


Originally posted by Vishal Vohra:
Secondly, according to the second part of the definition does Abstraction means defining classes.

I found these definitions almost everywhere, so does abstraction really mean hiding implementation details and if it does, then does it also brings out the concept of interfaces and abstract classes which only provides method signatures and hide out the actual implementation from the end user.



I think others have answered this, so I won't say much more that to echo the point that there are many different types of abstraction. The point you are asking about here is are classes abstractions. A "Person" class is an abstraction in that it is not really a living person (obviously). It is a programing construct used to represent a person (i.e. an abstraction). In an employee benefits program that abstraction will be very different than in a medical records application, which will be different than a X-Ray machine's internal code.

As mentioned, there are many different types and levels of abstraction. But it is a key concept. So kudos to you for working through it and asking questions. Keep asking until you understand it well. It will pay great dividends in the end.
[ August 21, 2008: Message edited by: Mark Vedder ]
 
What? What, what, what? What what tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic