+ 3
What is the benefit of using interface in PHP or any other programming language
I had seen intercept in oop concept and I also seen classes and not able to understand the difference in their usage
4 Réponses
+ 2
The main advantage of interfaces in PHP is that classes can implement multiple interfaces. This allows you to group classes that share some functionality but do not necessarily share a parent class. Some examples might include caching, output, or accessing properties of the class in a certain way.
From a site.
+ 1
@James Clark I. Vinarao where is it used
In a game
For which purpose
+ 1
It is mainly used in Object-Oriented Programming but you can also use it in creating games.
0
Think of the following case study in a game. There are two types of weapons. Knife and Gun. Knifes have their own different methods from Guns but one similarity - they can both be held in hand to use to conquer enemies. So the best approach is to do this
Interface Weapon
Class Knife inherits Weapon
Class Gun inherits Weapon
Class MachineGun extends Gun