Thursday, August 25, 2011

OOPS CONCEPTS


Encapsulation: A simple definition of encapsulation is - combining the data (information) and the methods (functions) that can manipulate that data into one capsule (class/object). Depending on how you write program encapsulation, it guarantees that the encapsulated data is not accessed by any other function/method/program outside the encapsulated object. For example,
class MyCapsule
{
private:
int myInt;
char myChar;
public:
MyIntFunc() { myInt = 10; }
MyCharFunc() { myChar = 'A'};
};

In this case, no other program/function/method can access myInt other than MyIntFunc. Same is true for myChar and MyCharFunc.

Abstraction: A simple definition of abstraction is to hide actual implementation of an object from the external world that would use the object. For example, a program that is drawing circles and squares using those objects need not know how those objects are implemented. It is enough for the program to know what the behavior of these objects is, and how to use these objects (rather than how these objects are implemented internally).

So, drawing a parallel between abstraction and encapsulation, when you encapsulate data and methods that operate on data into one object, the external program that uses this object need not know the internal workings of the object to use the object. Thus making the object abstract data type to the external program. Classic examples of abstract data type in C (yes) are int, char, float, double etc. Classes are OOPL variations and extensions of the traditional abstract data types.
------------------------------                      

OOP with VB

OOP Basics
Visual Basic was Object-Based, Visual Basic .NET is Object-Oriented, which means that it's a true Object-Oriented Programming Language. Visual Basic .NET supports all the key OOP features like Polymorphism, Inheritance, Abstraction and Encapsulation. It's worth having a brief overview of OOP before starting OOP with VB.
Why Object Oriented approach?

A major factor in the invention of Object-Oriented approach is to remove some of the flaws encountered with the procedural approach. In OOP, data is treated as a critical element and does not allow it to flow freely. It bounds data closely to the functions that operate on it and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. A major advantage of OOP is code reusability.

Some important features of Object Oriented programming are as follows:

     Emphasis on data rather than procedure
     Programs are divided into Objects
     Data is hidden and cannot be accessed by external functions
     Objects can communicate with each other through functions
     New data and functions can be easily added whenever necessary
     Follows bottom-up approach
Concepts of OOP:
     Objects
     Classes
     Data Abstraction and Encapsulation
     Inheritance
     Polymorphism
Briefly on Concepts:

Objects

Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code.

Classes

A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.

Data Abstraction and Encapsulation

Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.

Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it.

Inheritance

Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.

Polymorphism

Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.

Advantages of OOP

Object-Oriented Programming has the following advantages over conventional approaches:
     OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
     OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
     OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

No comments:

Post a Comment