0% found this document useful (0 votes)
45 views10 pages

Ooops Vansh Notes Ipu University

The document provides an overview of Object-Oriented Programming (OOP), detailing its applications in software, game, web, mobile app development, and more. It explains key OOP concepts such as encapsulation, abstraction, inheritance, and polymorphism, as well as the roles of constructors and destructors. Additionally, it covers access specifiers, generic programming, C++ stream classes, and the Standard Template Library (STL), highlighting their significance in creating efficient and maintainable code.

Uploaded by

Sahil Hans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views10 pages

Ooops Vansh Notes Ipu University

The document provides an overview of Object-Oriented Programming (OOP), detailing its applications in software, game, web, mobile app development, and more. It explains key OOP concepts such as encapsulation, abstraction, inheritance, and polymorphism, as well as the roles of constructors and destructors. Additionally, it covers access specifiers, generic programming, C++ stream classes, and the Standard Template Library (STL), highlighting their significance in creating efficient and maintainable code.

Uploaded by

Sahil Hans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Object-Oriented Programming (OOP) is widely used in various applications

due to its modularity, reusability, and ease of maintenance. Here are some
common applications:

1. Software Development: OOP is used to develop complex software


systems, such as operating systems, web browsers, and office
suites. Examples include Windows, macOS, and Microsoft Office.

2. Game Development: OOP principles are used to create interactive


and immersive games. Game engines like Unity and Unreal Engine
are built using OOP.

3. Web Development: OOP is used in server-side programming for web


applications. Frameworks like Django (Python), Ruby on Rails (Ruby),
and ASP.NET (C#) utilize OOP concepts.

4. Mobile App Development: OOP is used to develop mobile


applications for platforms like Android and iOS. Languages like Java,
Kotlin, and Swift are OOP-based.

5. Database Management: OOP is used in designing and managing


databases. Object-oriented databases like ObjectDB and
programming languages like SQL with OOP extensions are
examples.

6. Simulation and Modeling: OOP is used in scientific simulations and


modeling applications, such as weather forecasting, financial
modeling, and engineering simulations.

Key Advantages of Using OOP in Applications:

 Modularity: Easier to test and debug small components.

 Reusability: Classes and objects can be reused in different parts of


the system.

 Scalability: Suitable for large and complex applications.

basic concepts of oops

The Object-Oriented Programming (OOP) paradigm is a programming


model organized around objects rather than actions.

1. Encapsulation: This is the concept of bundling the data (attributes)


and methods (functions) that operate on the data into a single unit,
called a class. It hides the internal state of the object from the
outside world and only exposes a controlled interface.
2. Abstraction: This involves simplifying complex reality by modeling
classes appropriate to the problem. It allows you to focus on the
essential qualities of an object rather than the specific details.

3. Inheritance: This is a mechanism where a new class (derived class)


inherits properties and behaviors (methods) from an existing class
(base class). It promotes code reuse and establishes a natural
hierarchy between classes.

4. Polymorphism: This allows objects to be treated as instances of


their parent class rather than their actual class. It means a single
function can work in different ways depending on the object it is
acting upon. Polymorphism can be achieved through method
overriding and method overloading.

These principles help in creating modular, reusable, and maintainable


code. They are the foundation of OOP and are widely used in software
development to manage complexity and improve code quality.

Constructor vs destructor

Constructor :

1. Purpose: A constructor is a special member function that initializes


objects of a class. It sets up the initial state of an object.

2. Name: The constructor has the same name as the class.

3. Invocation: It is automatically called when an object of the class is


created.

4. Parameters: Constructors can have parameters (parameterized


constructors) or no parameters (default constructors).

5. Overloading: Constructors can be overloaded, meaning you can have


multiple constructors with different parameters in the same class.

6. Return Type: Constructors do not have a return type, not even void.

Destructor

1. Purpose: A destructor is a special member function that cleans up


when an object of the class is destroyed. It releases resources that
the object may have acquired during its lifetime.

2. Name: The destructor has the same name as the class, but with a
tilde (~) prefix.
3. Invocation: It is automatically called when an object goes out of
scope or is explicitly deleted.

4. Parameters: Destructors do not take any parameters.

5. Overloading: Destructors cannot be overloaded; there can only be


one destructor per class.

6. Return Type: Destructors do not have a return type, not even void.

ACCESS SPECIFIERS

There are three main access specifiers:

1. Public: Members declared as public are accessible from outside the


class. They can be accessed directly using the object of the class.

2. Private: Members declared as private are only accessible within the


class itself. They cannot be accessed directly from outside the
class.

3. Protected: Members declared as protected are accessible within the


class and by derived classes (subclasses). They are not accessible
from outside the class, but they can be accessed by any class that
inherits from the parent class.

Usefulness of Protected Access Specifier

The protected access specifier is particularly useful in inheritance. It


allows a base class to expose its members to derived classes while
keeping them hidden from the outside world.

GENERIC PROGRAMMING

Generic programming is a style of programming that focuses on writing


algorithms and data structures in a way that they can work with any data
type. This is achieved using templates in C++. Here are some key
advantages of generic programming:

1. Code Reusability: You can write a single function or class to work


with different data types, reducing code duplication.
2. Type Safety: Templates allow for type checking at compile time,
which helps catch errors early.

3. Performance: Since templates are resolved at compile time, there is


no runtime overhead, making generic programming efficient.

4. Flexibility: It allows for the creation of more flexible and adaptable


code, as the same template can be used with different data types.

5. Maintainability: With less code duplication, maintaining and


updating the code becomes easier.

Feature Compile-Time Polymorphism Run-Time Polymorphism

Polymorphism resolved at Polymorphism resolved at


Definition
compile time. runtime.

Alternate Also known as static Also known as dynamic


Name binding or early binding. binding or late binding.

Achieved through method


How It Achieved through method
overloading or operator
Works overriding and inheritance.
overloading.

Slightly slower, as the


Faster, as the method to
method to call is determined
Performance call is determined at
at runtime using virtual
compile time.
tables (vtable).

Requires inheritance and a


Inheritance Does not require
base class pointer or
Requirement inheritance.
reference.

Less flexible; the More flexible; allows different


Flexibility method behavior is behavior based on the actual
fixed at compile time. object type.
Techniques - Function overloading - Function overriding
Used - Operator overloading - Use of virtual functions

What is C++ Garbage Collection?

Garbage collection is a memory management technique. It is a


separate automatic memory management method which is used in
programming languages where manual memory management is not
preferred or done. In the manual memory management method, the
user is required to mention the memory which is in use and which
can be deallocated, whereas the garbage collector collects the
memory which is occupied by variables or objects which are no
more in use in the program. Only memory will be managed by
garbage collectors, other resources such as destructors, user
interaction window or files will not be handled by the garbage
collector.

Few languages need garbage collectors as part of the language for


good efficiency. These languages are called as garbage-collected
languages. For example, Java, C# and most of the scripting
languages needs garbage collection as part of their functioning.
Whereas languages such as C and C++ support manual memory
management which works similar to the garbage collector. There
are few languages that support both garbage collection and
manually managed memory allocation/deallocation and in such
cases, a separate heap of memory will be allocated to the garbage
collector and manual memory.

Some of the bugs can be prevented when the garbage collection


method is used. Such as:

 dangling pointer problem in which the memory pointed is


already deallocated whereas the pointer still remains and
points to different reassigned data or already deleted memory

 the problem which occurs when we try to delete or deallocate


a memory second time which has already been deleted or
reallocated to some other object
 removes problems or bugs associated with data structures and
does the memory and data handling efficiently

 memory leaks or memory exhaustion problem can be avoided

STATE BEHAVIOUR AND IDENTITY

In Object-Oriented Programming (OOP), an object is an instance of a


class and has three main characteristics: identity, state, and
behavior.

1. Identity: This is a unique identifier for the object. It


distinguishes one object from another, even if they have the
same state and behavior. In programming, the identity is often
represented by the object's memory address.

2. State: This refers to the data or attributes of the object. The


state represents the current condition of the object. For
example, in a Car class, the state could include attributes like
color, make, model, and speed.

3. Behavior: This refers to the methods or functions that the


object can perform. The behavior defines what the object can
do. For example, in a Car class, the behavior could include
methods like accelerate(), brake(), and turn().

Together, these characteristics define an object in OOP. The identity


ensures each object is unique, the state represents the data held by
the object, and the behavior defines the actions the object can
perform.

VECTORS

vector in oops

In Object-Oriented Programming (OOP), a vector is a dynamic array


that can grow and shrink in size. It is part of the C++ Standard
Template Library (STL) and provides a way to store and manage a
collection of elements. Here are some key features of vectors in
OOP:

1. Dynamic Size: Unlike arrays, vectors can change their size


dynamically. You can add or remove elements, and the vector
will automatically adjust its size.

2. Random Access: Vectors provide constant-time access to


elements using an index, similar to arrays.

3. Memory Management: Vectors handle memory allocation and


deallocation automatically, making them easier to use
compared to raw arrays.

4. Flexibility: Vectors can store elements of any data type,


including user-defined types (objects).

WHAT IS STL AND EXPLAIN DIFFERENT COMPONENT OF IT

The Standard Template Library (STL) in C++ is a powerful set of


C++ template classes to provide general-purpose classes and
functions with templates that implement many popular and
commonly used algorithms and data structures like vectors, lists,
queues, and stacks. Here are the main components of the STL:

1. Containers: These are used to store collections of objects.


They include:

o Sequence Containers: Such as vector, deque, list, and


array.

o Associative Containers: Such as set, multiset, map, and


multimap.

o Unordered Containers: Such as unordered_set,


unordered_multiset, unordered_map, and
unordered_multimap.

2. Algorithms: These are a collection of functions to perform


operations on the elements of containers. Examples include
sort, search, copy, transform, and accumulate.

3. Iterators: These are objects that point to elements within


containers. They are used to traverse the elements of a
container. Types of iterators include:
o Input Iterators: Read elements from a container.

o Output Iterators: Write elements to a container.

o Forward Iterators: Traverse a container in a forward


direction.

o Bidirectional Iterators: Traverse a container in both


forward and backward directions.

o Random Access Iterators: Access elements at any


position directly.

4. Functors (Function Objects): These are objects that can be


called as if they are functions. They are used to pass functions
as arguments to algorithms.

5. Adapters: These are special containers or iterators that


provide a different interface for the underlying container or
iterator. Examples include:

o Container Adapters: Such as stack, queue, and


priority_queue.

o Iterator Adapters: Such as reverse_iterator,


insert_iterator, and istream_iterator.

The STL provides a rich set of tools that make it easier to write
efficient and reusable code. It is a fundamental part of modern
C++ programming.

Key Differences Between Class and Structure

Aspect Class Structure

Default Access Private by default for Public by default for


Modifier members. members.

Typically used for


Intended Use Typically used for representing simple
representing complex data aggregates.
Aspect Class Structure

objects with both


data and behavior.

Supports
inheritance, but this
Inheritance Supports inheritance.
is rarely used in
structures.

Encapsulation is more
Encapsulation is less
common and aligns
Encapsulation common in
with object-oriented
structures.
principles.

Can include member Can also include


functions (methods), member functions,
Functions constructors, but traditionally
destructors, and used for grouping
access modifiers. variables.

Structures are
Supported only in C++
Compatibility supported in both C
and not in C.
and C++.

explain c++ stream classes


In C++, stream classes are part of the Input/Output (I/O) library
and are used for handling input and output operations. They
provide a way to read from and write to various sources like the
console, files, and strings. Here are the main stream classes in
C++:

1. iostream

 istream: This class is used for input operations. It provides


functions to read data from input sources like the keyboard or
files.
 ostream: This class is used for output operations. It provides
functions to write data to output destinations like the console
or files.

 iostream: This class is derived from both istream and ostream


and is used for both input and output operations.

2. fstream

 ifstream: This class is derived from istream and is used for


reading data from files.

 ofstream: This class is derived from ostream and is used for


writing data to files.

 fstream: This class is derived from both ifstream and ofstream


and is used for both reading from and writing to files.

3. sstream

 istringstream: This class is derived from istream and is used


for reading data from strings.

 ostringstream: This class is derived from ostream and is used


for writing data to strings.

 stringstream: This class is derived from both istringstream and


ostringstream and is used for both reading from and writing to
strings.

In C++, ‘this’ pointers is a pointer to the current instance of a


class. It is used to refer to the object within its own member
functions

You might also like