OOP (Object-Oriented Programming) — Abstraction
Abstraction means showing only essential details while hiding unnecessary complexity. It makes code easier to understand and use. For example, when you drive a car, you only use the steering wheel and pedals without knowing how the engine works internally. In OOP, abstraction is implemented using abstract classes or interfaces (depending on the language). This allows you to focus on what an object does rather than how it does it. Abstraction helps in reducing complexity and making the code more readable.
class Shape {
area() {
throw 'This method should be overridden';
}
}
class Circle extends Shape {
constructor(radius) {
super();
this.radius = radius;
}
area() {
return Math.PI * this.radius * this.radius;
}
}
let c = new Circle(5);
console.log(c.area());