Welcome to the Object-Oriented Programming (OOP) tutorial! OOP is a programming paradigm based on the concept of "objects", which can contain data and code:

🧱 Core Principles

  1. Encapsulation

    • Bundling data (attributes) and methods (functions) into a single unit (class)
    • Restricting direct access to an object's internal state using private/protected modifiers
    • 📌 Example:
      class BankAccount:
          def __init__(self, balance):
              self._balance = balance  # Protected attribute
      
          def deposit(self, amount):
              self._balance += amount
      
    Encapsulation
  2. Inheritance

    • Creating new classes from existing ones to reuse code
    • Parent class (base class) and child class (derived class) relationships
    • 📌 Example:
      class Animal:
          def speak(self):
              pass
      
      class Dog(Animal):
          def speak(self):
              return "Woof!"
      
    Inheritance
  3. Polymorphism

    • Ability of objects to take many forms
    • Overriding methods in subclasses or using interfaces
    • 📌 Example:
      def animal_sound(animal: Animal):
          print(animal.speak())
      
      animal_sound(Dog())  # Outputs: Woof!
      
    Polymorphism
  4. Abstraction

    • Hiding complex implementation details and showing only essential features
    • Using abstract classes or interfaces to define common behavior
    • 📌 Example:
      from abc import ABC, abstractmethod
      
      class Shape(ABC):
          @abstractmethod
          def area(self):
              pass
      
    Abstract_Concept

📚 Extend Your Knowledge

Ready to practice? Check out our OOP Examples section for hands-on exercises!

Let me know if you need further clarification 😊