Object-Oriented Programming
Object-Oriented Programming :
- OOP is the methodology to create a program using classes and
objects.
- A class is a blueprint of an object.
- Objects are the basic unit of OOP.
- OOP associated with the concept like Class, Object, Inheritance, Abstraction, Encapsulation, Polymorphism.
- It improves software development productivity
by providing Modularity, Reusability and Extensibility.
- Reusability enables the faster development and
lower the price of development.
- OOP is larger in size and slower is speed.
- OOP provide ability to simulate the real-world
events easily.
- It is easy to maintenance.
Advantages –
- Data security
- Inheritance
- Code reusability
- Flexible and Abstraction is also present.
Applications –
- It simplify a complex problem in a real-busines
system.
- Hundreds of windowing systems have been
developed using OOP techniques.
- OOP has enabled the software industry to
improve the quality of software system and also its productivity.
- Object-oriented technology is certainly
changing the way of software engineers think, analyze, design and
implement systems.
Procedural-Oriented Programming :
- POP is a type of computer programming language that follows the
step-by-step approach and procedures to execute methods and functions.
- It follows Up-Down approach.
- It separates the program within variable,
functions, statements and conditional operators.
- Focus of procedural programming is to break down the program into variables, data structures and subroutines.
e.g- C,
BASIC, FORTRAN, PASCAL etc.
Advantages –
- POP is simple to implement.
- It needs very less memory.
- An easy way to keep track of program flow.
- Global data can be accessed from anywhere in
the program.
Disadvantages –
- In POP, data is less secure.
- No data hiding mechanism.
- Difficult to relate with real-world objects.
- Complex problem cannot be solved.
- Overloading is not possible.
- It does not have any access specifier.
- It is less efficient and less productive.
Difference between Procedural-Oriented
Programming (POP) and Object-Oriented Programming (OOP) :
|
POP |
OOP |
1. |
It follows step-by step approach to execute a function and methods. |
Various functions can work simultaneously. |
2. |
It follows Top-Down approach. |
It follows Bottom-Up approach. |
3. |
It is less secure. |
It is more secure than POP. |
4. |
It needs very less memory. |
It needs more memory than POP. |
5. |
Programs are divided into functions. |
Programs are divided into objects. |
6. |
It deals with algorithm. |
It deals with data. |
7. |
It doesn’t have any access specifier. |
It has access specifier like Private, Public & Protected. |
8. |
Overloading is not possible in POP. |
Overloading is possible in the form of
Function Overloading and Operator Overloading. |
9. |
There is no data hiding mechanism. |
It is possible to hide data. |
10. |
Function communicates with each other
by passing parameters. |
Object communicate with each other by passing
message. |
Object in OOP :
- Object is a real-word entity.
- It has states(data) and
behaviour(functionality).
- Object is a runtime entity
which is created at runtime.
- Object is an instance of a class. All the
members of class can be accessed through objects.
Class in OOP :
- A Class is a group of similar objects.
- It is a blueprint or template form which
objects are created.
- It represents the set of
properties that are common to all the objects of one type.
- A class specification has two parts-
1) Private
2)
Public
- Private data can be accessed only within the
Class.
- Public data can be accessed from outside the
Class.
- The Keyword ‘Private’ is optional. By default, Class
Members are private.
- Each part has two types of elements-
1) Data Member
2)
Member Function
- The Variables (data member) and
Functions (member function) are collectively known as Class Member.
- General form of Class declaration-
class class_name { Private: Data member; Member function; Public: Data member; Member function; }; |
Create an Object in OOP :
- Create an object of a class like a variable creation
of some basic data type.
- Object is created in two places of program-
(1) In class immediately after the closing
curly bracket.
class book { Body of book; } b1, b2,
b3 ; //
declaration of objects |
(2) In main program.
class book { Body of book; }; int main() { book b1, b2, b3 ; // objects of class book } |
Constructor :
- It is a member function of class.
- It is always present in Public section of
class.
- It has same name as that of class.
- It is called automatically when an object of
the class is created.
- It is not returning any value (no return type)
even void also.
- It reserves memory.
- Constructor is declared as-
class student { private: int roll; char name[10]; public: student(); // Constructor
declaration }; |
Features of Constructor –
- Constructor is always declared in the Public
section.
- It is called automatically when an object of
the class is created.
- It has no return type not even
void.
- It cannot be inherited and virtual.
Destructor :
- It is a member function of class.
- It is always present in Public section of
class.
- It has same name as that of class but followed
by a special symbol ~ (tilde).
- It is called automatically when an object of
the class is destroyed.
- It is not returning any value (no return type)
even void also. It takes no argument.
- It destroys memory when called.
- Constructor is declared as-
class student { private: int roll; char name[10]; public: ~student(); // Destructor declaration }; |
Features of Destructor –
- Compiler itself called the Destructor when an
object is destroyed.
- It has no return type even void.
- It cannot be inherited and virtual.
- It is de-locate the memory that was allocated
by Constructor for the Object.
Difference between Constructure and
Destructure :
Constructure |
Destructure |
A constructor is called when a new instance of a class is created. |
Destructor called when an already existing instance of a class is
destroyed. |
Its name is same as class name. |
Its name is same as class name but
it preceded by tilde (~). |
It can take arguments. |
It doesn’t take any argument. |
It can be overloaded. |
It can’t be overloaded. |
Multiple constructors can coexist inside the class |
Only one destructor exists in a class. |
It is called each time a class is instantiated. |
It is called automatically when an
object is detected from memory. |
e.g – student (int a, int b) |
e.g – ~student () |
0 Comments
If you have any suggestion or doubt, please ask me.
Emoji