Object Oriented Programming



Object Oriented Programming


1.1   Concept of Object Oriented Programming
Object oriented programming was developed to reduce the inherent limitations of traditional programming languages. OOP treats data as critical element in the program and restricts the data to flow freely around the system. OOP allows decomposition of problem into number of entities called objects & then built data & functions around these objects. The data of an object can be accessed only by the functions associated with that object.

Features of Object Oriented Programming:-
·        Emphasis is on data rather than procedure.
·        Programs are divided into objects.
·         Data is hidden & cannot be accessed by external functions.
·         Objects may communicate with each other through functions.
·         Functions that operate on data of an object are tied together in data   structure.
·         Follows bottom-up approach.

1.2   Basic Concepts of OOP

Some of the concepts used in used extensively in OOP are:-
1.     Objects
2.     Classes
3.      Data Hiding
4.     Data Abstraction & Encapsulation
5.     Inheritance
6.     Polymorphism
7.     Dynamic Binding
8.     Message Passing     

1.   Objects -> It is an instance of class. It can be uniquely identified by its name & defines a state which is represented by the values of its attributes at a particular time. It may represent a place, a bank account, a table data that a program has to handle.
2.   Classes -> A class is an expanded concept of data structure. It is a collection        of both data and function together. Classes are declared using the                            keyword class.

3.   Data Hiding -> The insulation of data from direct access by the program is        called data hiding or information hiding.

4.   Data Abstraction & Encapsulation -> The wrapping up of data &               functions into a single unit is called encapsulation. It is the most striking             feature of a class. The data is not accessible to the outside world, and only                 those functions which are wrapped in the class can access it.
    Abstraction refers to the art of representing essential features without                  including the background details or explanations. Classes use the concept of        abstraction and are defined. They encapsulate all the essential properties of          the objects that are to be created. The attributes are sometimes called data                members because they hold information. The functions that operate on these          data are sometimes called methods or member functions. Since the classes use        the concept of data abstraction, they are known as, Abstract Data Types                 (ADT).

5.   Inheritance -> It is the process by which the objects of one class acquire         the properties of another class. The concept of inheritance provides the idea           of reusabilityE.g. The bird ‘Robin’ is a part of the class ‘flying bird’ which is           again part of the class ‘bird’.

6.   Polymorphism -> It means the ability to take more than one form. An              operation may exhibit different behaviors in different instances. For Example,          consider the operation of addition. For two numbers it will generate a sum. If        the operands are strings, then the operation would produce a third string by            concatenation.

7.   Dynamic Binding -> Binding refers to the linking of the procedure call            to  the code to be executed in response to the call. Dynamic Binding means                that  the code associated with a given procedure call is not known until the              time of the call at run – time. It is associated with polymorphism & inheritance.
     Consider the procedure “draw” in below fig.. By inheritance every object will           have this procedure. Its algorithm is, however, unique to each object & so the          draw procedure will be redefined in each class that defines the object. At run-          time, the code matching the object under current reference will be called.

8.   Message Passing -> An object-oriented program consists of a set of                     objects that communicate with each other. The process of programming in an         object-oriented language, therefore, involves the following steps. 


  • Creating classes that define objects & their behaviors.
  • Creating objects from class definition.
  •        Establishing communicating objects.

Objects communicate with each other by sending & receiving information much the same way as people pass messages to one another. The concept of message passing makes it easier to talk about building system that directly model or simulate their real world counterparts. A message for an object is a request for execution of procedure & therefore will invoke a function in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of function (message) & the information to be sent.
Objects have a life cycle. They can be created & destroyed. Communication with an object is feasible as long as it is alive.


1.3   Polymorphism (Function Overloading)

Function Overloading or Function Polymorphism allows multiple function to share the same name. Overloading means attaching more than one meaning to the same thing. Function Overloading means, functions with same name, but with many forms or many different definitions.
The key to function overloading is the function argument list. It is also called as the function signature. If two or more functions have the same number and type of arguments in the same order, we say that the two functions have same signature.
Example: An overload add() function handles different types of data as shown below:

// Declarations
int add(int a, int b);
int add(int a, int b, int c);
double add(double x, double y);
double add(int p, double q);

//Function Calls
cout<<add(5, 10);
cout<<add(5, 10.1);
cout<<add(5.2, 10.4);
cout<<add(0.45, 23);


Program

#include<iostream.h>
#include<conio.h>

int volume (int);                                         // declaration
double volume (double, int);
long volume (long, int, int);
void main()
{
            cout<< volume(10)<<”\n”;
            cout<< volume(2.5, 8)<<”\n”;
            cout<< volume(100, 50, 50)<<”\n”;
            getch();
}

int volume (int s)                                        // volume of cube
{
return (s*s*s);
}

double volume (double a, int b)              // volume of cylinder
{
return(3.14*a*a*b);
}

long volume (long l, int b, int h)              // volume of cuboid
{
return(l*b*h);

}

1.4   Advantages of OOP

·         Through inheritance, we can eliminate redundant code & extend the use of existing classes.
·         It is easy to maintain and modify existing code.
·         Software complexity can easily be managed.
·        Data hiding helps the programmer to build secure programs that can’t be invaded by code in other parts of the program.
·        The reuse of software lowers the cost of development.
·        Once an Object is created, knowledge of its implementation is not necessary for its use. 



1.5   Application of OOP
·               Client-Server Systems
·                Object Oriented Databases
·                Real-Time System Design
·                Simulation & Modelling System
·                Hypertext And Hypermedia
·                Neural Networking And Parallel Programming
·                Office Automation Systems
·                CIM/CAD/CAM Systems
·                AI Expert Systems




1.6   Disadvantages of C++

·        It has no security
·        Complex in a very large high-level program.
·        Used for platform specific application commonly.
·        For a particular operating system or platform, the library set has usually              chosen that locks.
·        When C++ used for web applications complex and difficult to debug.
·        C++ can’t support garbage collection.
·        C++ is not secure because it has a pointer, friend function, and global variable.
·        No support for threads built in.




    Comments

    Popular posts from this blog

    ASCII / ISCII / UNICODE

    CISC / RISC / EPIC

    Evolution of Computers