Академический Документы
Профессиональный Документы
Культура Документы
Object-oriented C++
C++ is not a pure object-oriented language because we can write the
code without the classes. It is object-oriented because it supports the
features provided by the object-oriented approach so it is a multi-
paradigm language.
Classes
A class is a user-defined data type which includes data members and
functions. It contains a similar type of objects. It is considered as a
blueprint of the object.
Example:
When we talk about birds then that is a class and when we talk about a
particular bird like sparrow then we are talking about the object.
Objects
These are the real world entities. Who exists in the real world that is
called objects like pen, pencil etc. And its class will be stationary.
Inheritance
Inheritance is the mechanism by which you can use the existing code. It
is used to decrease the program’s length. It means you can use all the
properties of a function or a complete class by inheriting it. It is based
on parent-child relationship. Existing class considered as Parent and the
new class is considered as child class. A child class can use the functions
and variables of the parent class.
Encapsulation
Encapsulation is the important concept of OOP. It binds the functions
and data together. It can be achieved by using classes with different
access specifiers.
Example:
It is similar to a capsule. A capsule contains many of the ingredients and
contains them in a single unit. So encapsulation means wrapping of
data and functions in a single unit.
Abstraction
Abstraction is used to hide the information which helps in avoiding the
interference of any external. It hides the information which is not
necessary for the user, but it performs its function as well. It is called
data hiding.
Example:
For the concept Data hiding, you can look at the fan. You just know
about the fan that it revolves and gives you the cooling without the
knowledge of internal working or mechanism of the fan, it is data
hiding. It means when the user only wants functionality only and not
interested in mechanism or information is not necessary for the user
the data hiding comes in use.
Polymorphism
Polymorphism is a combination of two words i.e Poly and morphs. Poly
means many and morph means forms. It is achieved by overloading and
overriding either it is operator overloading/overriding or function
overloading/overriding.
That part was describing it in real life but the next little part is what the
areas of C++ OOP will work with
Benefits of OOP:
It is easy to model a real system as real objects are represented by
programming objects in OOP. The objects are processed by their
member data and functions. It is easy to analyze the user requirements.
With the help of inheritance, we can reuse the existing class to derive a
new class such that the redundant code is eliminated and the use of
existing class is extended. This saves time and cost of program.
In OOP, data can be made private to a class such that only member
functions of the class can access the data. This principle of data hiding
helps the programmer to build a secure program that can not be
invaded by code in other part of the program.
With the help of polymorphism, the same function or same operator
can be used for different purposes. This helps to manage software
complexity easily.
Large problems can be reduced to smaller and more manageable
problems. It is easy to partition the work in a project based on objects.
It is possible to have multiple instances of an object to co-exist without
any interference i.e. each object has its own separate member data and
function.
REFERENCES
Stackoverflow.com
Scribd.com
Wikipedia.org
Tutorialink.com
Admecindia.co.in