1. Definition
  2. When to use
  3. How to Achieve
  4. Difference between Inheritance and Abstraction
  5. Difference between Encapsulation and Abstraction

1. Definition

Abstraction is the process of concealing the intricate internal workings of an object or system while exposing a simplified interface that highlights only the relevant aspects necessary for interaction. This allows users or developers to work with a system at a higher level, focusing on what the system does rather than how it achieves its functionality.

Key Points

In programming, this concept is applied through techniques such as:

// Protocol defining an abstract concept
protocol Shape {
    func area() -> Double
    func perimeter() -> Double
}

// Concrete class implementing the protocol
class Rectangle: Shape {
    var width: Double
    var height: Double
    
    init(width: Double, height: Double) {
        self.width = width
        self.height = height
    }
    
    func area() -> Double {
        return width * height
    }
    
    func perimeter() -> Double {
        return 2 * (width + height)
    }
}

2. When to use