The correct use of PHP interface class Interface _php tutorial

Source: Internet
Author: User
For those beginners

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

    1. Interface Shop
    2. {
    3. Public function Buy ($gid);
    4. Public function sell ($GID);
    5. Public Function view ($GID);
    6. }

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

 
  
  
  1. Class Baseshop implements Shop
  2. {
  3. Public function Buy ($gid)
  4. {
  5. Echo (' You have purchased the ID: '. $gid. ' goods ');
  6. }
  7. Public function Sell ($gid)
  8. {
  9. Echo (' You have sold the ID: '. $gid. ' goods ');
  10. }
  11. Public Function view ($gid)
  12. {
  13. Echo (' You have viewed the item ID: '. $gid. ');
  14. }
  15. }

You think, in a multi-person cooperation of large projects, with the interface class is how convenient, so you do not have to ask others, your method name of the function is what, of course, if you like this I have no way.

Conclusion: PHP Interface class interface is the leader of a class, indicating the direction, the subclass must complete its specified method.


http://www.bkjia.com/PHPjc/446183.html www.bkjia.com true http://www.bkjia.com/PHPjc/446183.html techarticle for those beginners actually their role is very simple, when there are a lot of people to develop a project, may be to call someone else to write some of the classes, then you will ask, how do I know his ...

  • Related Article

    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.