Sobes.tech
Junior — Middle

Can you explain the concept of abstraction in object-oriented programming?

sobes.tech AI

Answer from AI

Abstraction in object-oriented programming is a principle that allows hiding complex implementation details and showing only the necessary interface for interacting with an object. It helps simplify working with objects by focusing on what the object does, rather than how it does it.

For example, in PHP, you can create an abstract class with an abstract method that all subclasses are required to implement:

abstract class Vehicle {
    abstract public function move();
}

class Car extends Vehicle {
    public function move() {
        echo "The car is moving";
    }
}

$car = new Car();
$car->move(); // output: The car is moving

Here, the Vehicle class defines a common interface (the move method), and specific classes implement the details. The user interacts with the object through the abstract interface, without worrying about the internal implementation.

Can you explain the concept of abstraction in… - sobes.tech