1. Dynamic Binding
  2. Message Passing
  3. Object Cloning
  4. Wrapper Class

1. Dynamic Binding

Dynamic binding (also known as late binding) is a concept in programming where the method or function to be executed is determined at runtime rather than at compile time. This allows for more flexible and extensible code, particularly in object-oriented programming, where it enables polymorphism.

class Animal {
    func makeSound() {
        print("Some generic animal sound")
    }
}

class Dog: Animal {
    override func makeSound() {
        print("Bark")
    }
}

class Cat: Animal {
    override func makeSound() {
        print("Meow")
    }
}

func printAnimalSound(animal: Animal) {
    animal.makeSound()
}

let myDog = Dog()
let myCat = Cat()

printAnimalSound(animal: myDog)  // Output: Bark
printAnimalSound(animal: myCat)  // Output: Meow

2. Message Passing

How It Works:

  1. Message Sending: An object sends a message to another object by calling one of its methods.
  2. Message Handling: The receiving object processes the message by executing the method associated with it.
  3. Polymorphism: Different objects can respond to the same message in different ways based on their type.
class Animal {
    func makeSound() {
        print("Some generic animal sound")
    }
}

class Dog: Animal {
    override func makeSound() {
        print("Bark")
    }
}

func printAnimalSound(animal: Animal) {
    animal.makeSound()  // Message passing
}

let myDog = Dog()
printAnimalSound(animal: myDog)  // Output: Bark

3. Object Cloning

Types of Cloning

  1. Shallow Copy: