Monday, March 04, 2013

OOPS with JS - Part 3

in the 2nd part i have covered few basics about prototype object. some important points about prototype object in JavaScript.
  1. Every object have prototype property
  2. It holds an empty Object
  3. you can extend this object any time.
  4. you can have a constructor for this object.
before discussing more... encapsulation, inheritance, polymorphism, abstraction these are the principles of the any object oriented programming language. 

encapsulation is nothing but exposing or hiding your application objects / variables / components... to out side world (nothing but creating private / public methods, properties, variables, constants, lists... so on...
i will explain this by relating with real world...

when we saw the car on a road what we will see first - nothing but car body, wheels, seats, lights, bumpers..... we can't see engine inner parts unless we are dismantle it. so inner parts of the car like engine, hydraulic system, gear system, break systems are not seen by the out side world (nothing but encapsulation).

inheritance is a way to reuse the code of existing class or an object.every car is manufactured based on a engineering design..(this engineering design is nothing but a template - in our terms it is a class).

we can made N number of cars with the same template. we can have same characteristics for every car made based on that template. we don't required new templates for each car. we will have one template and reuse that to produce new ones (nothing but inheritance).

polymorphism means having more than one form...to simplify this --- a car may have lights. these lights can be used for different proposes, some time they might be used for singling the other vehicles on the road. night times they might be used for to view the road. same object but we are using for different proposes.

abstraction means recognizing common features and procedures of objects...to simple understanding... relating to existing world... every vehicle have wheel count... that may be a car, truck, auto....

we can simulate all above features in JavaScript we will have a look in the next post.....