Results 1 to 4 of 4

Thread: Abstraction !

  1. #1
    Senior Member PacketThirst's Avatar
    Join Date
    Aug 2004
    Posts
    258

    Abstraction !

    I've been learning a bit about OOPS lately. I understood the concept of "abstraction" .. But i couldn't understand its link with programming. Are you abstracting things from the user ??.
    If yes then does it make a real difference between ordinary sequential coding and OOPS as
    the user never has to bother about the elements of the program. The user gives the input and inturn gets the desired output. Where does abstraction really come into play in this ?.I guess i got the whole concept wrong .Do help me out ...


    PaCketThirst

  2. #2
    Senior Member
    Join Date
    May 2003
    Posts
    226
    Sometimes, a class that you define represents an abstract concept and, as such, should not be instantiated. Take, for example, food in the real world. Have you ever seen an instance of food? No. What you see instead are instances of carrot, apple, and (our favorite) chocolate. Food represents the abstract concept of things that we all can eat. It doesn't make sense for an instance of food to exist.

    Similarly in object-oriented programming, you may want to model an abstract concept without being able to create an instance of it. For example, the Number class in the java.lang package represents the abstract concept of numbers. It makes sense to model numbers in a program, but it doesn't make sense to create a generic number object. Instead, the Number class makes sense only as a superclass to classes like Integer and Float, both of which implement specific kinds of numbers. A class such as Number, which represents an abstract concept and should not be instantiated, is called an abstract class. An abstract class is a class that can only be subclassed-- it cannot be instantiated.
    Some nice reading: http://java.sun.com/docs/books/tutor.../abstract.html

    Though i have learnt abstraction but hardly use as well. Hope some experts would give more examples of the common usage

  3. #3
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Another example would be if you were wanting to create a game and had several different types of vehicles that all worked differently, you could create an abstact vehicle class that covered some things that all vehicles share, then leave the specifics to each individual class (like truck, plane, boat...) This is an example of using generalisation (or inheritance) coupled with abstraction to cut down the amount of code you are required to write, and also to enable code-reuse (which is like the holy grail of OOP)

    Hope that helped somewhat.

    ac

  4. #4
    Senior Member
    Join Date
    Feb 2004
    Posts
    270
    If you want a good view of abstraction, and other OOP things. Get yourself an unreal or Ut game and look at the Uscript. OOP at its best.
    Since the beginning of time, Man has searched for the answers to the big questions: \'How did we get here?\' \'Is there life after death?\' \'Are we alone?\' But today, in this very theatre, you will be asked to answer the biggest question of them all...WHO LIVES IN A PINEAPPLE UNDER THE SEA?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •