Basic concept of OOP in c++
Some Basic concept of OOP in c++
C++ What is OOP ?
OOP stands for Object-Oriented Programming.
Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.
Object-oriented programming has several advantages over procedural programming:
1. OOP is faster and easier to execute.
2. OOP provides a clear structure for the programs.
3. OOP helps to keep the C++ code DRY "Do not Repeat Yourself", and makes the code easier to maintain, modify and debug.
C++ What are Classes and Objects?
Class
When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.
Object
This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.
Abstraction
Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.
For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.
Encapsulation
The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users. To achieve this, you must declare class variables/attributes as private
. If you want others to read or modify the value of a private member, you can provide public get and set methods.
Inheritance
When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
It is useful for code reusability: reuse attributes and methods of an existing class when you create a new class.
Polymorphism
When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc.
In C++, we use Function overloading and Function overriding to achieve polymorphism.
C++ Function Overloading
Function Overloading is defined as the process of having two or more function with the same name, but different in parameters is known as function overloading in C++.
The advantage of Function overloading is that it increases the readability of the program because you don't need to use different names for the same action.
Comments
Post a Comment