+ 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

18th May 2020, 10:58 AM
Abhay
Abhay - avatar
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.
18th May 2020, 11:01 AM
James Clark I. Vinarao
James Clark I. Vinarao - avatar
+ 1
@James Clark I. Vinarao where is it used In a game For which purpose
18th May 2020, 11:03 AM
Abhay
Abhay - avatar
+ 1
It is mainly used in Object-Oriented Programming but you can also use it in creating games.
18th May 2020, 11:09 AM
James Clark I. Vinarao
James Clark I. Vinarao - avatar
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
18th May 2020, 11:50 AM
Ore
Ore - avatar