italofantone's avatar

In practice, what is abstraction?

I have read a lot about it but I don't get a practical explanation with PHP.

0 likes
5 replies
bugsysha's avatar

Abstraction is something more general than the thing you are talking about. Let's say that you have a chair. Abstraction for that might be furniture. Nothing more complicated than that. You can think of it as generalization.

rgillera's avatar

Something you cannot initialized. You cannot create object from it. It's mainly used for inheritance

italofantone's avatar

I have read about it and get two concepts, I would like to understand well.

  1. There is interface and abstract class.
  2. I read that the deficit of properties and methods is abstraction.

One concept applies to PHP and concept two applies to OOP.

There my confusion.

mikenewbuild's avatar

In your example, you could say OOP is the abstraction and PHP is the implementation ;-)

OOP is a concept and that can be implemented in multiple languages, but it has to conform to the concept of Classes/Methods/Inheritance etc. PHP implements these abstract concepts in a concrete way.

An abstract class specifically in PHP allows you to define some qualities that all classes derived from it will have.

Edit: importantly it doesn't say how you implement them, just that that all classes derived from it will inherit the abstract implementation by default.

It's worth looking into the discourse around the benefits of composition vs inheritance.

1 like

Please or to participate in this conversation.