Day 1 : Introduction to Object Oriented Programming(OOP)

OOP is used for simulating real world problems on computers because real world is made of objects.

The striking features of OOP include:
1. The programs are data-centered.
2. Programs are divided in terms of objects and not procedures.
3. Functions that operate on data are tied together with the data.
4. Data is hidden and not accessible by external functions.
5. New data amd functions can be easily added as and when required.
6. Follows a bottom-up approach for problem solving.

FEATURES OF OBJECT ORIENTED PROGRAMMING :

  1. Classes
    A class provides a template or a blueprint that describes the structure and behaviour of a set of similar objects. A class is a collection of objects of similar type. It is a user-defined data type that behaves same as the built-in data types.

\\ A sample student class
class student
{
private:
int roll_no;
char name[20];
float marks;
public:
get_details();
show_details();
}

C++ Classes and Objects - GeeksforGeeks

2. Objects
A class is used to create instances, known as objects. A class can have multiple instances. Every object contains some data and functions (also called methods). These methods store data in variables and respond to messages that they receive from other objects by executing their methods (procedures).

3. Method and Message Passing
A method is a function associated with a class. It defines the operations that the object cab execute when it receives a message. Only methods of the class can access and manipulate the data stored in an instance of the class(or object).
The data that is transferred with the message is called parameters.

4. Inheritance
Inheritance is a concept of OOP in which a new class is created from an existing class. The main advantage of inheritance is the ability to reuse the code. The new class, known as sub-class or derived class, inherits the attributes and behaviour of the pre-existing class, which is reffered to as super-class or parent class. When a sub-class can inherit properties and methods from multiple parent classes. This is called multiple-inheritance.

Explore the 5 Types of Inheritance in C++ with Syntax & Example - DataFlair
https://www.google.com/url?sa=i&url=https%3A%2F%2Fdata-flair.training%2Fblogs%2Finheritance-in-cpp%2F&psig=AOvVaw2bIZ1i7zC0e4waTW4Jrz5h&ust=1625253500767000&source=images&cd=vfe&ved=0CAoQjRxqFwoTCPClvaDLwvECFQAAAAAdAAAAABAD

5. Polymorphism: Static Binding and Dynamic Binding
Polymorphism is a concept that enables the programmers to assign a different meaning or usage to a variable, function, or an object in different contexts.
> When polymorphism is applied on variables, the variable with a given name may be allowed to have different forms. The program will then decide which form to use.
> Polymorphism can also be applied to a function in such a way that depending on the parameters it is given, a particular form of the function can be selected for execution. This type of polymorphism is called function overloading.
> Polymorphism can also be applied to operators. Example, a+b will give the result of adding a and b. If a=2 and b=3, then a+b=5.
All types of polymorphism we have discussed so far are better known as compile time polymorphism or static binding.
Dynamic binding or late binding, also known as run time polymorphism, is a feature that enables programmers to associate a function call with a code at the execution time.

6. Containership
The ability of a class to contain object(s) of more classes as member data. For example, class One can have an object of class Two as its data member. This would allow the object of class One to call the public functions of class Two. Here, class One becomes the container, whereas class Two becomes the contained class.

7. Genericity
To reduce code duplication abd generate short, simpler code, C++ supports the use of generic codes (or templates) to define the same code for multiple data types.

Reusability
Reusability means developing codes that can be used either in the same program or in different programs. Reusability is attained through inheritance, containership, polymorphism, and genericity.

8. Delegation
To provide maximum flexibilty to programmers and to allow them to generate a reusable code, object oriented languages also support delegation, also known as composition or containership.
In delegation, more than one object is involved in handling a request. The object that receives the request for a service, delegates it to another object called its delegate.

9. Data Abstraction and Encapsulation
Data abstraction refers to the process by which data and functions are defined in such a way that only essentials details revealed and the implementation details are hidden. The main focus of data abstraction is to seperate the interface and the implementation of a program.
Data encapsulation, also called data hiding, is the technique of packign data and functions into a single component (class) to hide implementation details of a class from the users.

Creating a new data type using encapsulated items that is well suited for an application is called data abstraction.

Difference Between Data Abstraction and Encapsulation - Pediaa.Com

Hope you learned something today! Thankyou for visiting!

Leave a comment

Design a site like this with WordPress.com
Get started