interfaces in PHP. Simple example open

interfaces in PHP. Simple example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: PHP 7

Interfaces are instructions for creating your classes. We cannot create a body of our methods in the interface

Lets create interfaces for our imaginary character properties:

interface Multiplyable{
        //create a property that will be needed in the future will be described in the class that uses this interface
	public function multiple(int $mult);
}

interface Transportable{
	public function moveTo();
}

interface Destroyable{
	public function destroy();
}

interface LiveUnit{
	public function makeAction();
}

Like classes, one interface can inherit another:

interface IOnGameCard extends Multiplyable, Transportable, Destroyable, LiveUnit{
}

Now let’s use our class interfaces:

class Animal implements LiveUnit, Transportable, Destroyable{
	public function moveTo(){}
	public function destroy(){}
	public function makeAction(){}
}

class Wall implements Destroyable{
	public function destroy(){}
}

class Stone implements Transportable, Destroyable{
	public function moveTo(){}
	public function destroy(){}
}

class Seaweed implements Transportable, Destroyable, Multiplyable{
	public function moveTo(){}
	public function destroy(){}
	public function multiple(){}
}
Interfaces in PHP. Code examples open
Interfaces in PHP. Code examples
May 17, 2022
Roman-tk
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation