0% found this document useful (0 votes)
13 views25 pages

Oops

Uploaded by

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

Oops

Uploaded by

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

4 PILLARS OF OBJECT

ORIENTED
PROGRAMMING
ABHIJEET SINGH
WHAT IS OOPs

 Object-Oriented Programming or OOPs refers to languages that use


objects in programming.
 Object-oriented programming aims to implement real-world
entities like inheritance, hiding, polymorphism, etc in
programming.
 The main aim of OOP is to bind together the data and the functions
that operate on them so that no other part of the code can access
this data except that function.
ABSTRACTION

 Abstraction as the name includes abstract it means the process of


hiding all the internal details and displaying the necessary things.
 In java the abstraction works to displays the essential functionality
to user, and hide other implementation of program to user
 The abstraction is achieved by using 2 ways abstract class and
interface
 An abstract class is declared using abstract keyword
 An interface is the blueprint of behaviour of class
ADVANTAGES OF ABSTRACTION

 Simplicity: Abstraction helps in reducing complexity of program


by displaying only essential features of a program
 Maintainability: Abstraction separates interface from
implementation which helps developers to apply changes to
internal code without affecting that how system interact with user
 Modularity: Abstraction breaks down complex programs into
smaller blocks and independent modules which helps to develop
and test the code separately
 Logic Focusing: Developers can focus on solving higher-level
problems without worrying about the lower-level details, allowing
more efficient problem-solving and development.
DISADVANTAGES OF ABSTRACTION

 Difficult Debugging: Abstraction hides the internal working of a


program to display only essential data, it leads to difficulties in
tracking the errors in a program
 Misuse: In some cases, developers might create an overly generalized
interfaces or classes that are too broad to be practical. This can lead to
inefficient or confusing designs.
 Over-Abstraction: Introduction of too many abstraction layers in a
program cause misunderstanding, because it creates program complex
and hard to understand for beginners.
 Time Consumption: Designing abstract interfaces or classes may
require more thought and effort upfront, which can increase
development time, particularly for smaller projects where
abstraction may not be necessary.
ENCAPSULATION

 Encapsulation is a way of hiding the implementation details of a


class from outside access and only exposing a public interface that
can be used to interact with the class.
 In Java, encapsulation is achieved by declaring the instance
variables of a class as private, which means they can only be
accessed within the class.
ADVANTAGES OF ENCAPSULATION

 Data Protection: Encapsulation helps protect sensitive data by


restricting access to it through private fields and providing controlled
access through methods
 Maintainability: Combination of data and methods within a class,
encapsulation promotes a modular approach to coding. If changes are
needed, they can be made without affecting other parts of the code.
 Flexibility: Encapsulation allows flexibility in modifying the internal
implementation of a class without altering the external interface.
 Reduces Human Error: By controlling how data is accessed and
modified, encapsulation reduces the chances of unintentional or
improper use of the class's internals, thus reducing bugs.
DISADVANTAGES OF
ENCAPSULATION

 Overhead Methods: Encapsulation often requires additional methods


(getters and setters) to access private data. This may add extra code
and complexity, especially in larger systems.
 Performance Impact: Accessing data through getter/setter methods
instead of directly can introduce a slight performance overhead
 Complexity: Over-encapsulation, where every piece of data is hidden
behind getter/setter methods, can lead to excessive code, making the
system harder to understand and maintain.
 Development Effort: Designing encapsulated classes with proper
access control can require more effort and planning during the
initial stages of development, which may not be necessary for
smaller, simpler projects.
INHERITANCE

 Inheritance means creating new classes based on existing ones.


 A class that inherits the properties of other class is known as child class
 A class whose properties get inherited by other class is known as parent class
ADVANTAGES OF INHERITANCE

 Reusability: Inheritance allows to reuse existing code from the parent


(superclass) in the child (subclass), reducing redundancy. This can save time and
effort, as common functionality does not need to be rewritten.
 Consistency: By inheriting from a common parent class, multiple subclasses
maintain consistent behavior and design, which promotes uniformity in code
structure across the application.
 Maintenance: When a change is made to a method or property in the parent
class, it automatically reflects in all child classes. This simplifies code
maintenance, as changes need to be made in only one place.
 Extensibility: Inheritance enables you to extend or modify the
functionality of an existing class without altering the original code.
Subclasses can override or extend methods to provide specific
behaviors, adding flexibility.
DISADVANTAGES OF INHERITANCE

 Complexity: Inheritance can make code more complex, especially when the
hierarchy becomes deep. Understanding the flow of data and method calls
across multiple levels of inheritance can be challenging for developers.
 Flexibility: Inheritance can limit flexibility because a subclass is strictly
bound to the design and structure of its parent class.
 Base Class Problem: Changes to the base (parent) class can inadvertently
affect all derived (child) classes. For example, adding or modifying a
method in the base class could override a subclass method or introduce new
behaviors that break the existing code.
 Overhead: Deep inheritance hierarchies may introduce a
performance overhead, as method calls need to traverse through the
hierarchy. Additionally, large inheritance trees can increase
memory consumption.
TYPES OF INHERITANCE

 Single Inheritance: A subclass inherits from one super-class.


 Multiple Inheritance: A subclass inherits from more than one
superclass (not supported in some languages like Java, but is in C++).
 Multilevel Inheritance: A subclass inherits from another sub-class.
 Hierarchical Inheritance: Multiple subclasses inherit from the same
super-class.
 Hybrid Inheritance: A combination of two or more types of
inheritance.
USE OF EXTENDS OVER IMPLEMENTS

 extends keyword is used to inherit a class or interface, while


implements keyword is used to implement the interfaces.
 A class can extend only one class but can implement any number
of interfaces.
 A subclass that extends a superclass may override some of the
methods from superclass, but implements all method from interface
POLYMORPHISM

 The word ‘polymorphism’ means ‘having many forms’.


 Java Polymorphism as the ability of a message to be displayed in more than one form.
ADVANTAGES OF POLYMORPHISM

 Reusability: Polymorphism allows the same method to be used in


different ways, reducing the need to write multiple methods for
similar actions.
 Flexibility: By allowing objects of different types to be treated as
instances of a common base type, polymorphism increases the
flexibility of code.
 Maintainability: Since the same interface or method name is used
for different types, maintaining and updating code becomes easier.
Changes made in a base class and all polymorphic methods will
automatically reflect these changes.
 Extensibility: With polymorphism, you can add new subclasses
without altering existing code. This makes it easier to scale
applications as new features or behaviors can be introduced with
minimal disruption to the existing structure.
DISADVANTAGES OF POLYMORPHISM

 Complexity: Polymorphism can increase code complexity, especially when


combined with other OOP concepts like inheritance. Understanding how
methods behave across different subclasses can become challenging for
beginners
 Runtime Errors: In case of dynamic polymorphism (method overriding), the
actual method to be executed is determined at runtime. This can introduce
runtime errors if the object doesn’t support the expected behavior.
 Misuse: Polymorphism can be overused or misused in situations where simpler
alternatives would suffice. Overloading and overriding methods unnecessarily
can lead to confusing and inefficient code.
 Difficult Debugging and Testing: Since polymorphism involves
method overloading and overriding, debugging can become
difficult. Determining which method is being called at runtime may
require a thorough understanding of the class hierarchy and the
overall system
TYPES OF POLYMORPHISM

Compile-time (Static Polymorphism): Achieved through method


overloading or operator overloading.
Runtime (Dynamic Polymorphism): Achieved through method
overriding where the decision happens at runtime.

You might also like