Sei sulla pagina 1di 21

Basics of Object Oriented Programming & C++

Topics to be Covered:

Paradigm of Programming
Language
The term paradigm describes a set of techniques, methods ,
theories and standards that together representing a way of
thinking for problem solving.

Structured Programming
Structured paradigm is based on the principle of
building a program from logical structures.
Structured programming follows the principle of divide
and conquer
Structured paradigm generally follows the top down
approach where the complex programming blocks are
broken into smaller blocks maintaining a well defined
structure and organization of the overall program

Object-Oriented Programming
Everything is focused on objects. Program
consists of two things:

First, a set of objects


Second, the way they interact with each other.
Examples are : C++, Smalltalk and Java.

Structured Vs
Object Oriented System
Structure programming is a subset of object-oriented
programming. Therefore OOP can help in developing
much larger and complex programs than structured
programming.
In Structure programming focus of a program in
manipulation of data but In OOP focus of program in
both the data and manipulation
In Structure data is in the form of variables but in OOP
data is hidden with in the objects

OBJECTS
An Object is an instance of a class.
are the real world models.
They may represent a person , a place, a bank account,
a table of data or any item that the program has to
handle.
They contain their own data and behaviors.
For example, Maruti is an instance of the class Cars.
Zen is another instance of the class Cars. All the cars
have similar features such as wheels, brake, seat.

CLASS
A class is a collection of objects of similar type. ExMango, apple, orange are members of the class fruit.
Once a class has been defined , we can create any
number of objects belonging to that class.
Objects are variables of the type class.

Information Hiding
Information hiding concept restricts direct exposure of
data. Data is accessed indirectly using safe mechanism,
methods in case of programming object. Taking bike as

an example, we have no access to the piston directly, we


can use 'start button' to run the piston.

Information Hiding Example

class Time
{
public:
void Display();
private:
int ticks;
};

Encapsulation

The wrapping up of data and functions into


a single unit (called class) is known as
encapsulation. Encapsulation refers to how
the implementation details of a particular
class are hidden from all the objects
outside of the class

Example
class Adder{
public:
Int total;
void addNum(int number)
{
total += number;

int main( )
{
Adder

a.total=0;
a.addNum(10);

a.addNum(20);

int getTotal()
{
return total;

};

a;

a.addNum(30);
cout << "Total " << a.getTotal()
<endl;
return 0;

};
}

Message Passing
Message Passing is nothing but sending and
receiving of information by the objects same as people
exchange information. So this helps in building
systems that simulate real life. Following are the basic
steps in message passing.
Creating classes that define objects and its behavior.
Creating objects from class definitions
Establishing
communication
among
objects
In OOPs, Message Passing involves specifying the
name of objects, the name of the function, and the
information to be sent.

Interface

An Interface of class or an object is a collection of


signatures of all the methods contained in the class

or the object. It is through this interface, the


objects communicate

with themselves or other

objects by passing value of variables to and fro.

Inheritance
It is a technique of organizing information in
a hierarchical form.
It is like a child inheriting the feature of its
parents. It is an ability to derive new class
from existing classes.
A derive class is known as sub class which
inherits the instance variable and methods
of super class or base class and can add
some new instance variables and methods.

Inheritance to be cont.
In OOP, the concept of inheritance provides the idea
of reusability.
This means that we can add additional features to an
existing class without modifying it.

This is possible by deriving a new class from the


existing one.
The new class will have the combined features of
both the classes.

Polymorphism
Poly means many and morphism means
form I.e. many forms.
It means the ability to take more than one
form or actions of same property.
Same functions with same function name
can perform different actions depending
upon which object call the function.

Method Overloading

Method Overriding

Benefits of Object-Oriented
Programming
The Object oriented programming allows breaking complex
large software programs to simpler, smaller and manageable
components.
1.
2.
3.
4.
5.
6.
7.

Modular Design
Simple approach
Modifiable
Extensible
Flexible
Reusable
Maintainable

Potrebbero piacerti anche