The correct use method of PHP interface class interface ____php

Source: Internet
Author: User
Tags php language

For those beginners of the PHP language, for the PHP interface class may not be very in-depth understanding, and then we will specifically describe the PHP interface class interface usage.

In fact, their role is very simple, when a lot of people together to develop a project, may go to call someone else to write some of the class, then you will ask, how do I know how he is the implementation of a function of how to name it, this time the PHP interface class interface play a role, when we define an interface class, The way inside it is that the following subclasses must be implemented, such as:


Interface Shop  
{public  
     function buy ($gid);  
     Public function sell ($gid);  
     Public Function view ($gid);  
  

I declare a shop interface class, defined three methods: Buy (purchase), sell (Sell), see (view), then inherit this class all subclasses must implement these 3 methods less than one, if the subclass does not implement these words, can not run. In fact, the interface class plainly, is a class template, a class of provisions, if you belong to this category, you must follow my rules, less than one, but the specific how you do, I do not care, it is your business, such as:


Class Baseshop implements  shop {public  
     function buy ($gid) {  
         echo (' you purchased the product with ID: '. $gid. ');  
     }  
     Public function Sell ($gid) {  
	echo (' You sold the product with ID: '. $gid. ');  
     }  
     Public Function View ($gid) {  
	echo (' You have viewed the product with ID: '. $gid. ');  
     }  
  

You think, in a large number of people cooperation project inside, have the interface class is how convenient, so you do not have to ask others, your certain function of the method name is, of course, if you like this I have no way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.