1. Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects",
which can contain data and code: data in the form of fields (often known as attributes or properties),
and code, in the form of procedures (often known as methods). A structure is a collection of
variables of different data types under a single unit. It is almost similar to a class because both are
user-defined data types and both hold a bunch of different data types.
Pillars of OOP
Data Abstraction
Encapsulation
Inheritance
Polymorphism
WHAT IS OOP
2. It hides the internal implementation and creates the skeleton of what is required for that entity. This is achieved
by creating a class and defining the member variables, properties and methods inside it as per requirement.
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.
Abstraction
3. It hides data from external world. It protects data within class and expose methods to the world. This is
achieved using access modifiers like private, public protected and internal.
Encapsulation is one of the fundamentals of OOP (object-oriented programming). It refers to the bundling of
data with the methods that operate on that data. Encapsulation is used to hide the values or state of a
structured data object inside a class, preventing unauthorized parties' direct access to them.
Encapsulation is placing the data and the functions that work on that data in the same place. While working
with procedural languages, it is not always clear which functions work on which variables but object-oriented
programming provides you framework to place the data and the relevant functions together in the same object.
Encapsulation
4. One of the most useful aspects of object-oriented programming is code reusability. As the name suggests
Inheritance is the process of forming a new class from an existing class that is from the existing class called as
base class, new class is formed called as derived class.
This is a very important concept of object-oriented programming since this feature helps to reduce the code
size.
Explain diamond problem and give solution Solving diamond problem through interfaces or generics
The "diamond problem" (sometimes referred to as the "Deadly Diamond of Death") is an ambiguity that arises
when two classes B and C inherit from A, and class D inherits from both B and C. ... It is called the
"diamond problem" because of the shape of the class inheritance diagram in this situation.
The solution to this problem is ‘virtual’ keyword. While inheriting from A class B and C should inherit class A as
virtual public.
Inheritance
5. The ability to use an operator or function in different ways in other words giving different meaning or functions
to the operators or functions is called polymorphism. Poly refers too many. That is a single function or an
operator functioning in many ways different upon the usage is called polymorphism.
Overloading
The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to
operate on new data type, it is said to be overloaded.
Polymorphism
6. A Smart Pointer is a wrapper class over a pointer with an operator like * and -> overloaded. The objects of
the smart pointer class look like normal pointers. But, unlike Normal Pointers it can deallocate and free
destroyed object memory.
The idea is to take a class with a pointer, destructor and overloaded operators like * and ->. Since the
destructor is automatically called when an object goes out of scope, the dynamically allocated memory
would automatically be deleted (or reference count can be decremented). Consider the following simple
SmartPtr class.
Smart pointers
7. A C++ functor (function object) is a class or struct object that can be called like a function. It overloads the
function-call operator () and allows us to use an object like a function.
They store the starting address or entry point of the memory block comprising all the instructions of
a function in greater detail.
The main benefit of function pointers is that they provide a straightforward mechanism for choosing a
function to execute at run-time.
they can easily preserve a state between calls. In other words, they can support multiple
independent states, one for each functor instance while functions only support a single state.
Allow to add state to the function objects. A state object can store arrays that can be updated with a
response from an API or users
FUNCTERS
8. The containers in the C++ standard library are:
• Sequence containers: vector, deque, list, forward_list, array
• Associative containers: set, multiset, map, multimap
• Unordered associative containers: unordered_set, unordered_multiset, unordered_map,
unordered_multimap
• Container adaptors: stack, queue, priority_queue
• Smart pointers: unique_ptr, shared_ptr, weak_ptr
Containers