Object oriented programming paradigms
Object-Oriented Programming (OOP) paradigms refer to the principles and concepts that define the
structure and behavior of object-oriented programs. These paradigms focus on the use of objects
and classes to create modular, reusable, and maintainable code. Here are the key OOP paradigms.
Class and Object Paradigm
 Class: A blueprint or template for creating objects. It defines properties (attributes)
and behaviors (methods) that the objects created from the class will have.
 Object: An instance of a class. It encapsulates data and behavior related to that data.
Each object created from a class has its own set of attributes and can interact with
other objects.
2. Encapsulation
 Encapsulation is the bundling of data (attributes) and methods (functions) that operate
on the data into a single unit, known as 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. This is typically
achieved using access modifiers (e.g., private, protected, public).
 Benefits: Improves modularity, enhances security, and makes the code easier to
maintain and understand.
3. Inheritance
 Inheritance allows a new class (derived or child class) to inherit attributes and
methods from an existing class (base or parent class).
 It promotes code reusability and establishes a relationship between the parent and
child classes.
 Single Inheritance: A class inherits from one parent class.
 Multiple Inheritance: A class inherits from more than one parent class (not
supported in some languages like Java).
4. Polymorphism
 Polymorphism allows objects to be treated as instances of their parent class rather
than their actual class. The exact method that is invoked is determined at runtime.
 Compile-time Polymorphism: Achieved through method overloading (same method
name with different parameters within the same class).
 Runtime Polymorphism: Achieved through method overriding (child class provides
a specific implementation of a method that is already defined in its parent class).
5. Abstraction
 Abstraction is the concept of hiding the complex implementation details and showing
only the essential features of an object.
 It helps in reducing programming complexity and effort by providing a simplified
model of the system.
 Abstract Classes: Classes that cannot be instantiated and are meant to be subclassed.
They can have abstract methods (methods without implementation) that must be
implemented by derived classes.
 Interfaces: Define a contract that implementing classes must follow. They can only
declare methods but not implement them.
6. Composition
 Composition is a design principle where a class is composed of one or more objects of
other classes. This relationship is known as a "has-a" relationship.
 It is used to model more complex behaviors by combining simpler, reusable
components.
7. Association, Aggregation, and Composition
 Association: A general binary relationship that describes an activity between two
classes. It can be one-to-one, one-to-many, or many-to-many.
 Aggregation: A special form of association that represents a "whole-part"
relationship where the part can exist independently of the whole.
 Composition: A stronger form of aggregation where the part cannot exist
independently of the whole. If the whole is destroyed, the part is also destroyed.
8. Message Passing
 Objects communicate with each other through messages (method calls). This allows
objects to interact and collaborate to perform a task.
 It promotes loose coupling between objects, making the system more modular and
flexible.
9. Dynamic Binding
 Dynamic binding (or late binding) is the process of linking a procedure call to a
specific method at runtime rather than compile-time.
 It allows for more flexible and reusable code, as the exact method to be called is
determined based on the object type at runtime.
10. Interfaces and Implementation
 Interfaces: Define a contract of methods that a class must implement without
providing the method implementations.
 Implementation: The actual code that fulfills the contract defined by the interface.
Multiple classes can implement the same interface, providing different behaviors.

CS3391 Object oriented programming paradigms.docx

  • 1.
    Object oriented programmingparadigms Object-Oriented Programming (OOP) paradigms refer to the principles and concepts that define the structure and behavior of object-oriented programs. These paradigms focus on the use of objects and classes to create modular, reusable, and maintainable code. Here are the key OOP paradigms. Class and Object Paradigm  Class: A blueprint or template for creating objects. It defines properties (attributes) and behaviors (methods) that the objects created from the class will have.  Object: An instance of a class. It encapsulates data and behavior related to that data. Each object created from a class has its own set of attributes and can interact with other objects. 2. Encapsulation  Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data into a single unit, known as 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. This is typically achieved using access modifiers (e.g., private, protected, public).  Benefits: Improves modularity, enhances security, and makes the code easier to maintain and understand. 3. Inheritance  Inheritance allows a new class (derived or child class) to inherit attributes and methods from an existing class (base or parent class).  It promotes code reusability and establishes a relationship between the parent and child classes.  Single Inheritance: A class inherits from one parent class.  Multiple Inheritance: A class inherits from more than one parent class (not supported in some languages like Java). 4. Polymorphism  Polymorphism allows objects to be treated as instances of their parent class rather than their actual class. The exact method that is invoked is determined at runtime.  Compile-time Polymorphism: Achieved through method overloading (same method name with different parameters within the same class).  Runtime Polymorphism: Achieved through method overriding (child class provides a specific implementation of a method that is already defined in its parent class). 5. Abstraction  Abstraction is the concept of hiding the complex implementation details and showing only the essential features of an object.  It helps in reducing programming complexity and effort by providing a simplified model of the system.
  • 2.
     Abstract Classes:Classes that cannot be instantiated and are meant to be subclassed. They can have abstract methods (methods without implementation) that must be implemented by derived classes.  Interfaces: Define a contract that implementing classes must follow. They can only declare methods but not implement them. 6. Composition  Composition is a design principle where a class is composed of one or more objects of other classes. This relationship is known as a "has-a" relationship.  It is used to model more complex behaviors by combining simpler, reusable components. 7. Association, Aggregation, and Composition  Association: A general binary relationship that describes an activity between two classes. It can be one-to-one, one-to-many, or many-to-many.  Aggregation: A special form of association that represents a "whole-part" relationship where the part can exist independently of the whole.  Composition: A stronger form of aggregation where the part cannot exist independently of the whole. If the whole is destroyed, the part is also destroyed. 8. Message Passing  Objects communicate with each other through messages (method calls). This allows objects to interact and collaborate to perform a task.  It promotes loose coupling between objects, making the system more modular and flexible. 9. Dynamic Binding  Dynamic binding (or late binding) is the process of linking a procedure call to a specific method at runtime rather than compile-time.  It allows for more flexible and reusable code, as the exact method to be called is determined based on the object type at runtime. 10. Interfaces and Implementation  Interfaces: Define a contract of methods that a class must implement without providing the method implementations.  Implementation: The actual code that fulfills the contract defined by the interface. Multiple classes can implement the same interface, providing different behaviors.