Oop Ca1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Oops : Design And Concepts

NAME OF THE STUDENT: SAHIL KUMAR


DEPARTMENT: COMPUTER SCIENCE & ENGINEERING
PAPER NAME: OBJECT ORIENTED PROGRAMMING
PAPER CODE:PCC-CS503
INSTITUTION NAME: PAILAN COLLEGE OF MANAGEMENT AND TECHNOLOGY
INTRODUCTION
Object-oriented programming (OOP) is a programming paradigm that revolves around the concept
of objects. These objects can contain both data (referred to as fields, attributes, or properties) and
code (in the form of methods). Let me break it down further:

• Objects: In OOP, we design computer programs by creating and interacting with objects. Each
object represents a specific entity or concept. For example, if you’re building a banking
application, you might have objects like “Account,” “Customer,” and “Transaction.”

• Data (Fields/Attributes/Properties): Objects store data related to their characteristics. These


attributes define the state of an object. For instance, an “Account” object might have attributes
like account number, balance, and account holder name.

• Code (Methods): Objects also contain code (methods) that define their behavior. Methods allow
objects to perform actions or respond to specific events. For example, an “Account” object
could have methods like “deposit,” “withdraw,” and “getBalance.”

OOP promotes modularity, reusability, and better organization of code


Basic Concepts of OOP
1. Objects:

An object is an instance of a class. It represents a specific entity or concept in the real world. For example, if
you have a “Car” class, an object of that class could be a specific car with its unique characteristics (color,
make, model, etc.).

2. Classes:

A class is a blueprint or template for creating objects. It defines the attributes (data) and methods (functions)
that objects of that class will have. Think of it as the general description of what an object should look like.

3. Attributes (Fields/Properties):

Attributes (also called fields or properties) are the data members of a class. They represent the state of an
object. For instance, a “Person” class might have attributes like “name,” “age,” and “address.”

4. Methods (Functions):

Methods define the behavior of objects. They are functions associated with a class. For example, a
“BankAccount” class could have methods like “deposit,” “withdraw,” and “getBalance.”

• Remember, these concepts form the foundation of OOP, allowing developers to create well-organized,
reusable, and maintainable code.
Pillars of OOP
1. ENCAPSULATION:

Definition: Encapsulation involves bundling data (attributes) and methods (behavior) together within a
class. It hides internal complexities and exposes only necessary interfaces.

Purpose: Encapsulation ensures that data is accessed and modified through well-defined methods
(getters and setters), preventing direct manipulation and maintaining dataintegrity.

Example: Think of a Bird class with properties like color and legs. Encapsulation allows us to control how
these attributes are accessed and modified1.

2. INHERITANCE:

Definition: Inheritance allows a class (called a subclass or derived class) to inherit attributes and methods
from another class (called a superclass or base class). It promotes code reuse.

Purpose: By inheriting common features (like wings, eyes, etc.), we avoid redundant declarations. For
instance, a Pigeon class can inherit from the general Bird class1.
3. POLYMORPHISM:

Definition : Polymorphism enables objects to take on multiple forms. It allows different


classes to implement the same method in their own way.

Purpose : Polymorphism enhances flexibility. For example, both a Circle and a Rectangle
class can have a calculateArea method, each behaving differently1.

4. ABSTRACTION:

Definition : Abstraction simplifies complex systems by focusing on essential features while


hiding implementation details. It provides a high-level view.

Purpose : Abstraction allows us to create generic functions or objects that serve multiple
purposes. For instance, abstracting away coffee-making details into a simple button
interface1.

• Remember, these pillars form the foundation of OOP, enabling better code
organization, reusability, and maintainability.
OOP Design Principles
❑ Single-Responsibility Principle (SRP):

• A class should have one and only one reason to change. In other words, it
should have a single responsibility.

• Example: Consider an AreaCalculator class that calculates the sum of areas


for different shapes. Instead of handling both area calculation and output
formatting, split these responsibilities into separate classes1.

❑ Open-Closed Principle (OCP):

• Software entities (classes, modules, functions) should be open for extension


but closed for modification.

• In practice, this means you can add new functionality (extensions) without
altering existing code. Achieve this through interfaces, abstract classes, and
inheritance1.
❑ Liskov Substitution Principle (LSP):

• Objects of a superclass should be replaceable with objects of a subclass without


affecting the correctness of the program.

• Inheritance hierarchies should maintain behavioral compatibility. Avoid violating


expectations of derived classes

❑ Interface Segregation Principle (ISP):

• Clients (classes or modules) should not be forced to depend on interfaces they don’t
use.

• Split large interfaces into smaller, more specific ones. This prevents unnecessary
dependencies and promotes cleaner designs1.

❑ Dependency Inversion Principle (DIP):

• High-level modules should not depend on low-level modules. Both should depend on
abstractions (interfaces or abstract classes).

• Decouple components by relying on abstractions rather than concrete


implementations. Inversion of control (IoC) containers can help achieve this
Common OOP Languages
• Java: Widely used in enterprise applications, Android development,
and web services1.
• Python: Known for its simplicity, readability, and versatility.
• C++: A powerful language used in systems programming, game
development, and performance-critical applications.
• JavaScript: Primarily used for web development (both front-end and
back-end) and building interactive web applications.
• C#: Developed by Microsoft, commonly used for Windows
applications, game development (with Unity), and web services.
• Ruby: Known for its elegant syntax and used in web development (with
Ruby on Rails) and scripting
Conclusion
Certainly! In conclusion, Object-Oriented Programming (OOP) is a
powerful paradigm that enhances code organization, reusability,
and maintainability. By understanding concepts like classes,
objects, encapsulation, inheritance, polymorphism, and
abstraction, developers can create robust and efficient software
systems.
Remember that OOP is not just about syntax—it’s a mindset that
shapes how we design and build applications. Whether you’re
working with Java, Python, C++, or any other OOP language, these
principles remain fundamental.
THANK YOU

You might also like