Alex_Raj member offline |
|
posts: |
99 |
joined: |
05/16/2006 |
from: |
San Jose, CA |
|
|
|
|
|
Features of OOP |
Encapsulation Enforces Modularity and Reusibility
Encapsulation refers to the creation of self-contained modules that bind processing functions to the data. These user-defined blueprint module is called "class" and all instances of a class are called "objects". For example, a Employee class specifies data fields like name, address and telephonenumber. Alice and Bob are two objects of Employee class.
Inheritance Passes "Knowledge" Down
Inheritance is the creation of one class, called the derived (or child) class, from another class called the base (or parent) class. The derived class has all the features of the base class, plus some additional features. For example, Secretary class might be derived from a more general Employee class, and includes a data member called typingSpeed that Employee class lacked.
Inheritance lets the structure and methods in one class pass down the hierarchy. That means less programming is required when adding functions to complex systems. The ability to reuse existing objects is considered a major advantage of object technology.
Polymorphism Takes any Shape
Polymorphism involves treating objects of different classes in the same way. For polymorphism to work, these different classes must be derived (inherited or implemented) from the same base class or interface.
For example, a base class Animal's method speak() can trigger runtime binding objetcs' different behavior of speaking: "WongWong" for Dog and "MewMew" for Cat.
Polymorphism lets programmers create procedures for objects whose exact type is not known until runtime. Polymorphism simplifies and clarifies program design and coding.
|
|
|
|
|
|