Sunday, March 6, 2011

Object Oriented Programming (OOP)

Introduction

  • Object oriented programming is a replacement for structural programming.
  • It is a new way of organizing and developing programs.
  • All programming languages are not suitable to implement OOP concepts easily. C++ is a one of most popular OOP language today.
  • The latest one is JAVA ,  a pure object oriented language. But still you can write structural programs with JAVA.  
  • OOP allow us to decompose a problem in to a number of entities called objects and then build data and function(methods) around these entities.
Benefits of OOP

  • Eliminate redundant code.
  • Save time and high productivity.
  • Secure program.
  • Possible to have multiple objects.
  • Software complexity can be easily managed.
Class

A class describes the properties and behavior of common set of entities.
Classes are not REAL  .

Object

An object is an instance of a class. From one class we can create many instances.
Object are REAL
They are the basic runtime entities in program.


Ex:-


class Student{
            String name;
            String  address;

            Void study(){
                        System.out.println(“Studying”);
}
Void getDetails(){
            System.out.println(“My name is ”+name);
            System.out.println(“I live in  ”+address);
}

            public static void main(String args[]){
                        Student s1 = new Student();                
                        S1.name = “Saman”;
                        S1.address = “Maharagama”;
                        Student s2 = new Student();
                        S2.name = “Nuwan”;
                        S2.address = “Piliyandala”;
                       
                        S1.study();
                        S1.getDetails();

                        S2.study();
                        S2.getDetails();

}
}


You can create many objects according to the designed template. Simply that is OOP.

-Thank you-

2 comments: