Sunday, June 13, 2010

Understanding Object Oriented Programming Principles: Encapsulation, Inheritance, Polymorphism and Abstraction

Encapsulation:
Means putting the data and the function that operates on that data in a single unit(information hiding) .Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.
Encapsulation is the mechanism that binds together code and the data it manipulates,and keeps both safe from outside interference and misuse.in java encapsulation is achieved by making use of access modifiers( keeping variables as private and providing public getters and setters.

Eg:-
automatic transmission of an automobile.
It encapsulates lots of information about the engine, such acceleration, the pitch of the surface , and the position of the shift
lever. Being a user,we have only one method of affecting this complex encapsulation: moving the gear-shift lever.

Inheritance:
Inheritance is the process by which one object acquires the properties of another object.

Eg:-Vehicle->motorized->4wheeled.

Polymorphism:
Polymorphism (from the Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions.

Eg. Car's steering ->one interface many implementations(power or rack and pinion)

Abstraction:
Means hiding the internal details and just exposing the functionality.

Eg:-When we change the gear of a car, we know the gears will be changed without knowing how they are functioning internally.
Abstraction focuses on the outside view of an object (i.e. the interface).

5 comments:

  1. Anonymous4:00 AM

    nice article..

    ReplyDelete
  2. Anonymous8:54 PM

    good one man ..
    Yeh dil maangey more.

    ~GS

    ReplyDelete
  3. this is common thing i hope everybody knw so plz can u elobrate the encapuslation with real time exp.
    any way keep it up.

    ReplyDelete
  4. very easy way of understanding

    ReplyDelete
  5. Simple and humple,very good example

    ReplyDelete