Tuesday 16 July 2013

Distinguish between Data Abstraction and Data Encapsulation?

Data Abstraction:-Data abstraction means get the desired things.In data abstraction we use the features which we want ,without worry about the implementation.We have not the information how it will be done?Lets have an of real world example
You usually use mobile phone,when you do a call to your friend.Which steps you take (1)Type the number(2)Press the call button.


But you do not know what happens after that how the mobile implement this task to connect you with your friend..So the mobile has only abstract operation only which are type the number and press the call button.

Same as this example we have function of a object in programming, which done the particular task, these functions will do the task in there internal code only without showing it publicly.

Dummy code example:-
You might listen about the Stack which work on the principle to LIFO(Last In First Out).Stack have two operation PUSH and POP.So this function will do the data abstraction means these will do the internal work without telling the internal implementation.User will just use these two functions to do the task.
class Stack
{
       int numbers[]=new number[10];
       int top;
      Stack()
      {
         top=-1;
       }
      public void PUSH(int num)
      {
        ------------------
       }
       int void POP()
       {
        ------------------
        }

     public static void main(String ar[])
     {
             Stack marks=new Stack();
              marks.PUSH(10);
              marks.PUSH(20);
              int get=marks.POP();
           
}
\Note:-this Example is given to understand the concept only it will not be complied by the compiler.Please do not worry we will do this in proper format when you will have the knowledge about syntax etc in coming posts.



Data Encapsulation:-Data Encapsulation means wrapping the data and methods in a single unit.In programming class do the Encapsulation.Like capsule wrap up the medicine in it.

Example:-

class Chair
{
             int height;
             String color;
              Char()
              {
                 
                }
                public void setColor(String col)
                {
                           color=col;
                }
                ------
                ----------
}

So the Chair class is wrapping up the data members and methods in it

     






Thursday 4 July 2013

Distinguish between Object and class?


Object:-Object is a entity which remain active in the system(Like we are a object which remain active in the world).The Object can represent a person,a place,a bank account etc which is handle by the program.So in programming every problem is analysed in terms of objects and there nature of communication(Like in world we communicate with others ).So when a program is executed these objects  reaming active in system and interact  by sending messages to each other.Remember that these objects do not know the internal details of each others.Lets take an example how objects communicate:-

Objects Communication

When you go to Bank you have to communicate with some one to get information same as objects communicate with each other to exchange information,like in above example the program(software)developed to manage bank account data,that program will have two objects one will be Customer and other will be Account(remember that at the project level there will be so many objects will be created) and they will communicate to do bank transaction.

Class:-We know every objects have data and methods code  to manipulate the data.(like we have some attributes and functionality).The entire set of data and methods code of an object can be made user defined data type using the class.Once a class is defined we can create any number of objects belonging to that class.Example:-

Class Student
{
      String  Name ;
      int age;
      Student(String nm,int ag)
      {
          Name=nm;
          age=ag;
      }
      public static void main(String arg[])
      {
          Student Steve=new Student("Stave",21);
          Student John=new Student("John",19);
}

So in above example student is a class,Stave and John are objects of Student class

Tuesday 2 July 2013

What are the advantages of Object Oriented Programming Approach?

There are Following Advantages of Object Oriented Programming:-

  • Using Inheritance we can remove the redundant code and can extends the existing classes.
  • We can develop the programs in standalone modules that communicate with each other to do specific task,so we can start the development from already available code and we do not required to start from scratch.(we will see later how to use the already available code in class packages)
  • Using the principle of data hiding helps the programmers to develop secure programs that cannot hacked.
  • We can add the new features(modules) in a software code ,without effecting the previously working modules.
  • We can match the objects and their working easily.
  • It is easy to understand the working of complex objects in object oriented programming.