• Abstraction in java

    Abstraction

    An essential element of object oriented programming is abstraction. We manage complexity through abstraction. For example, we don’t think car as a set of tense of thousands of individual parts instead we think of it as a well-defined object, with its own unique behavior. This allows us to driving a car by only learning how to drive and not how the internal components of the car work.
    A powerful way to manage abstraction is through hierarchical classification. This allows us to layer the semantics of complex systems by breaking them more manageable pieces. Hierarchical abstractions of complex systems can also be applied to computer programs. The data from a traditional process oriented program can be transform by abstractions into it component object. A sequence of process steps can become a collection of messages between these objects. Thus each of these objects describes its unique behavior. We can create this objects as concrete entities that respond to messages, telling them to do something. This is the essence of object oriented programming.

    Example:

    class Num
    {
    int n;
    Num (int n)
              {
    this.n= n;
              }
              boolean is Even()
              {
                        if (n%2==0)
                        {
                                  return true;
                        }
                        else
                        {
                                  return false;
                        }
              }
    viod show()
    {
    System.out.println(n);
    }
    }
    class Evenchecker
    {
    public static void main (String []s)
    {
    Num a= new Num();
    if (a. is even())
    {
    System.out.println(“Even”);
    }
    else {
    System.out.println(“Odd”);
    }
    }

    }

    In this code the entire program semantic is divided into layers. If a programmer wants to use methods of ‘Num’ object, he/she could use it without knowing the implementation of the methods. Programmer only treats the methods as black box objects. This is possible because of abstraction. Like in our example is Even method may be called by a programmer who don’t know the implementation of is Even method. That’s how abstraction reduces complexity of a program.
  • You might also like

    No comments:

    Post a Comment

search topics

NEWSLETTER

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!