0

объектно-ориентированный php

Часто ли используются интерфейсы в ооп и какие цели при этом достигаются?

17th Sep 2018, 5:45 AM
Виктор Потоцкий
Виктор Потоцкий - avatar
1 Réponse
+ 1
Hi, I am Bulgarian, so I kind of get what you’re trying to say. Translate my answer with Google Translate: Interfaces are a must when talking about OOP PHP. They are mostly used to define what the methods of a class are. When you create an interface, you can get an excellent knowledge of what a certain class does. For example you will have interface PersonInterface with a method: public function eat(): void. In interfaces we just show the abstraction of the method. The implementation would be class Person implements PersonInterface {// here goes the implementation of our eat func}. With that we can now use Type-Hinting: /** @var PersonInterface */ $person = new Person(); Interfaces are the largest level of abstraction.
7th Sep 2019, 7:08 PM
Dimitar
Dimitar  - avatar