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.
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)
}
}