filmov
tv
Interface in PHP OOP | PHP OOP Lecture 12 | How to do this

Показать описание
Interface in PHP OOP, What is Interface in PHP OOP
#InterfaceInPhpOOP,#WhatIsInterfaceInOOP,#HowToDoThis
Interface:
An interface is similar to a class except that it cannot contain code.
An interface can define method names and arguments, but not the contents of the methods.
Any classes implementing an interface must implement all methods defined by the interface.
A class can implement multiple interfaces.
An interface is declared using the "interface" keyword.
Interfaces can't maintain Non-abstract methods.
Interfaces allow you to specify what methods a class should implement.
Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism".
Interfaces are declared with the interface keyword:
PHP - Interfaces vs. Abstract Classes
Interface are similar to abstract classes. The difference between interfaces and abstract classes are:
Interfaces cannot have properties, while abstract classes can
All interface methods must be public while abstract class methods may also be private or protected
All methods in an interface are abstract, so they cannot be implemented in code and the abstract keyword is not necessary
Classes can implement an interface while inheriting from another class at the same time
PHP - Using Interfaces
To implement an interface, a class must use the implements keyword.
A class that implements an interface must implement all of the interface's methods.
From the example above, let's say that we would like to write software which manages a group of animals. There are actions that all of the animals can do, but each animal does it in its own way.
Using interfaces, we can write some code which can work for all of the animals even if each animal behaves differently.
#InterfaceInPhpOOP,#WhatIsInterfaceInOOP,#HowToDoThis
Interface:
An interface is similar to a class except that it cannot contain code.
An interface can define method names and arguments, but not the contents of the methods.
Any classes implementing an interface must implement all methods defined by the interface.
A class can implement multiple interfaces.
An interface is declared using the "interface" keyword.
Interfaces can't maintain Non-abstract methods.
Interfaces allow you to specify what methods a class should implement.
Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism".
Interfaces are declared with the interface keyword:
PHP - Interfaces vs. Abstract Classes
Interface are similar to abstract classes. The difference between interfaces and abstract classes are:
Interfaces cannot have properties, while abstract classes can
All interface methods must be public while abstract class methods may also be private or protected
All methods in an interface are abstract, so they cannot be implemented in code and the abstract keyword is not necessary
Classes can implement an interface while inheriting from another class at the same time
PHP - Using Interfaces
To implement an interface, a class must use the implements keyword.
A class that implements an interface must implement all of the interface's methods.
From the example above, let's say that we would like to write software which manages a group of animals. There are actions that all of the animals can do, but each animal does it in its own way.
Using interfaces, we can write some code which can work for all of the animals even if each animal behaves differently.