oop (1)
oop (1)
oop (1)
Oriented
Programming)
2 Each object created from a class has It doesn't represent anything specific but rather
its own unique set of values for the describes a general concept.
attributes defined by the class.
3 Example: If Car is the class, then Example: A Car class might define attributes like
myCar (with color = red, model = sedan, color, model, and year, and methods like drive()
year = 2022) is an object of that class. and stop().
Another object could be yourCar with
different values for the same attributes.
Polymorphism
• Polymorphism is a concept in Object-Oriented
Programming (OOP) that allows objects of different
classes to be treated as objects of a common super
class.
• It means "many forms" and enables the same operation
to behave differently on different classes.
• Polymorphism allows for flexibility and extensibility in
code.
• It enables you to write more generic and reusable code,
where functions and methods can operate on objects of
different types, but with a common interface.
Polymorphism
Inheritance
• Inheritance is a fundamental concept in
object-oriented programming (OOP) that
allows a class to inherit properties and
behaviors (i.e., methods) from another
class.
• This helps in creating a hierarchical
relationship between classes, promotes
code reusability, and simplifies
maintenance.
Types of inheritance
• Single Inheritance: The derived class inherits from only one
base class.
• Multiple Inheritance: The derived class inherits from more than
one base class.
• (Note: Some languages like Java do not support multiple
inheritance directly but allow it through interfaces.)
• Multilevel Inheritance: A class is derived from another
derived class, creating a chain.
• Hierarchical Inheritance: Multiple classes inherit from a
single base class.
• Hybrid Inheritance: A combination of two or more types
of inheritance.
Types of inheritance
Encapsulation
• Encapsulation refers to the bundling of
data (attributes) and methods (functions)
that operate on that data into a single unit,
typically a class.
• It restricts direct access to some of an
object's components, which means that
the internal representation of an object is
hidden from the outside world.
Encapsulation
Abstraction/Data hiding
• It involves the concept of hiding the
complex implementation details of a
system and showing only the essential
features or functionalities.
• Abstraction allows programmers to focus
on what an object does rather than how it
does it, simplifying the development and
usage of complex systems.
Abstraction/Data hiding
Advantages of OOP
• OOP systems can be easily upgraded from small to
large systems.
• OOP language allows to break the program into the bit-
sized problems that can be solved easily (one object at a
time).
• By using inheritance, we can eliminate redundant code
and extend the use of existing classes.
• The principle of data hiding helps the programmer to
build secure programs which cannot be invaded by the
code in other parts of the program.
Disadvantage of oop
• Steeper Learning Curve: OOP
concepts like inheritance, polymorphism,
encapsulation, and abstraction can be
complex for beginners to understand.
• Complex Design: Designing a good
object-oriented system often requires
careful planning and a deep
understanding of the problem domain.
Disadvantage of oop
• Memory Overhead: OOP can result in
increased memory usage due to the creation
of many objects, each carrying its state and
behavior.
• Execution Overhead: The dynamic method
dispatch and the added indirection of accessing
properties and methods through objects can
lead to slower execution compared to procedural
programming, which is more straightforward and
can be optimized more easily by compilers.
Disadvantage of oop
• Overhead for Simple Problems: For simple problems,
using OOP can be overkill. The added complexity of
defining classes, methods, and objects might not be
justified, leading to more code and reduced clarity.
• Less Efficient for Certain Applications: Some
applications, especially those that require high
performance, such as real-time systems or system-level
programming, might not benefit from OOP. In these
cases, procedural or functional programming paradigms
might offer more control and better performance.
Application of OOP
• Desktop Applications: OOP is
extensively used in developing desktop
applications like word processors, graphic
design software, and games.
• Web Development: Many web
development frameworks, such as Django
(Python), Ruby on Rails (Ruby), Laravel
(PHP), and ASP.NET (C#), are based on
OOP principles.
• Game Development: OOP is a natural
fit for game development due to its ability
to model real-world entities as objects.
• Enterprise Resource Planning (ERP)
Systems: ERP systems, which integrate
various business processes such as
accounting, inventory management, and
human resources, often use OOP
principles to create modular components.
• Android and iOS Apps: Mobile
development frameworks and languages
like Java (for Android), Kotlin (for
Android), Swift (for iOS), and Objective-C
(for iOS) are built on OOP principles.
Difference between structural
and oop
S.N OOP POP