Inheritance is an OOP concept where one class inherits the properties and methods of another class. In Swift, only classes support inheritance — structs and enums don't have it.
Inheritance is great for reusing shared behavior, but overusing it when it's not really needed can make your code harder to understand. In Swift, protocol composition with structs is also widely used as an alternative.
swift
class Notification {
func send() {
print("Sending notification...")
}
}
class EmailNotification: Notification {
override func send() {
print("Sending email notification")
}
}
let email = EmailNotification()
email.send()EmailNotification inherits from Notification. Since we want to give the parent class's send() method its own behavior in the child class, override is used.
You should see
Sending email notification