Object Oriented Programming Concepts

By | July 28, 2023

Object Oriented Programming Concepts

1. Class

A class serves as a blueprint or template defining the structure and behavior of objects. It specifies attributes (data members) and methods (functions) that objects of that class will possess.

2. Object

An object represents an instance of a class, embodying a real-world entity with unique state (attribute values) and behavior (methods). Objects are created based on the class definition.

3. Instance Variable ( Data Member in C++ )

In Object-Oriented Programming (OOP), a data member, also known as an instance variable or attribute, is a variable associated with a specific class. It represents the state or characteristics of objects created from that class.

4. Method   ( Member Function in C++ )

In object-oriented programming, a method is a procedure linked to a class. It specifies the behavior of objects created from that class. In other words, a method represents an action that an object can execute. Note: In C++ a method is called “Member Function”.

5. Constructor

A constructor is a special method or function that is automatically called when an object of a class is created. It is used to initialize the object’s state and set up its initial values or properties.

6. Encapsulation

Encapsulation bundles data (attributes) and methods (behaviors) operating on the data within a single unit (class). It restricts access to internal details, enhancing data security and hiding implementation complexities.

7. Inheritance

Inheritance allows a class (subclass or derived class) to inherit attributes and methods from another class (superclass or base class). It fosters code reuse and establishes a hierarchical relationship between classes.

8. Polymorphism

Polymorphism permits objects of different classes to be treated as objects of a common superclass. This concept enables a single interface (method or function) to handle various object types, providing flexibility and extensibility in the code.

9. Abstraction

Abstraction focuses on essential object features while concealing unnecessary implementation details. It simplifies an object’s behavior, enhancing code manageability and reducing complexity.

10. Association

Association represents a relationship between two or more classes, where objects of one class relate to objects of another class. It may denote a simple connection or involve multiplicity, indicating the number of objects involved.

11. Aggregation

Aggregation depicts a specific form of association, where one class contains or is composed of other classes. It represents a “whole-part” relationship between classes.

12. Composition

Composition represents a stronger form of aggregation, where the lifespan of contained objects depends on the lifespan of the containing object. Upon the destruction of the containing object, the contained objects are also automatically destroyed.

13. Message Passing

In OOP, objects interact by sending messages to each other. A message is a request to perform a specific operation or method on the receiving object.

14. Destructor  (C++)

A destructor is a special member function in object-oriented programming languages like C++. It used to clean up resources and perform necessary cleanup tasks before an object is destroyed or deallocated. It is the counterpart of a constructor, which is responsible for initializing an object when it is created.

In C++, a destructor is defined using a tilde (~) symbol followed by the class name and no parameters. Example of constructor and destructor is as follows:


class MyClass {
public:
    // Constructor
    MyClass() {
        // Initialization code here
    }

    // Destructor
    ~MyClass() {
        // Cleanup code here
    }
};

Note:
In Java, the idea of destructors, which is commonly found in languages like C++, is not present. Instead, Java uses a diffrent approach to manage object cleanup and resource handling. It uses Garbage Collection mechanism.

15. Access Modifiers

Access modifiers are keywords in object-oriented programming languages that define the visibility and accessibility of class members (variables, methods, and inner classes) from other parts of the program. They control how these members can be accessed and modified by different classes or parts of the code. Examples of access modifiers are private, public and protected etc.

These concepts collectively constitute the foundation of Object-Oriented Programming, offering a systematic and modular approach to software design and development.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *