-
-
//1. Define some methods, and the subclass must fully implement all methods in this abstraction - //2. Objects cannot be created from abstract classes. The meaning of this is Being extended
- //3. Abstract classes usually have abstract methods, and there are no braces in the methods
- //4. Abstract methods do not have to implement specific functions, and are completed by subclasses
- //5. Implement methods of abstract classes in subclasses When, the visibility of its subclass must be greater than or equal to the definition of the abstract method
- //6. The method of the abstract class can have parameters or be empty
- //7. If the abstract method has parameters, then the implementation of the subclass also Must have the same number of parameters
///////////////////////////////Interface class Definition:
- interface Shop{
- public function buy($gid);
- public function sell($gid);
- abstract function view($gid);
- }
- //If you want to use the interface, you must define all the parameters in the interface class No method can be missing (except abstract).
- //In this way, if in a large project, no matter how others do the following method, they must implement all the methods in this interface!
- //Example: Implement the above A method of the interface
- class BaseShop implements Shop{
- public function buy($gid){
- echo 'You purchased the product with the ID:' . $gid . '';
- }
- public function sell($gid){
- echo 'You purchased and sold products with ID:' . $gid . '';
- }
- public function view($gid){
- echo 'You browsed products with ID:' . $gid . '';
- }
- }
//Example of multiple inheritance of interface:
- interface staff_i1{ //Interface 1
- function setID();
- function getID();
- }< /p>
interface staff_i2{ //Interface 2
- function setName();
- function getName();
- }
class staff implements staff_i1,staff_i2{
- private $id ;
- private $name;
- function setID($id){
- $this->id = $id;
- }
function getID(){
- return $this->id ;
- }
function setName($name){
- $this->name = $name;
- }
function getName(){
- return $this->name;
- }
function otherFunc(){ //This is a method that does not exist in the interface
- echo “Test”;
- }
- }
- ?>< ;/p>
-
Copy code
|