PHP implements a complete simple multi-state application instance based on interface technology, and php interface multi-state instance

Source: Internet
Author: User

PHP implements a complete simple multi-state application instance based on interface technology, and php interface multi-state instance

This example describes how PHP implements simple multi-State applications based on the interface technology. We will share this with you for your reference. The details are as follows:

<? Php // a simple instance that implements polymorphism interface USB {// The method permission in the interface must be public, and only the abstract method or constant function mount (); function work (); function unmount ();} class Upan implements USB {function mount () {echo "the USB flash disk is mounted successfully !! <Br> ";} function work () {echo" the U disk is working ...... <Br> ";} function unmount () {echo" the USB flash drive is unmounted !! <Br> ";}} class ShuBiao implements USB {function mount () {echo" USB mouse inserted successfully! <Br> ";} function work () {echo" the USB mouse is working ...... <Br> ";} function unmount () {echo" USB mouse removed! <Br> ";}} class DianNao {function useUSB ($ usb) {// This Is A polymorphism. When the input parameter is different from the usb device, call the same method name of different devices, but produce different results $ usb-> mount (); $ usb-> work (); $ usb-> unmount () ;}} class Worker {function install () {$ dn = new DianNao; // activate the computer $ up = new Upan; // activate the USB flash drive $ sb = new ShuBiao; // activate the mouse $ dn-> useUSB ($ up); // access the USB flash drive from your computer $ dn-> useUSB ($ sb ); // computer access mouse }}$ usb_user = new Worker; // user who activates a USB device $ usb_user-> install (); // how does the User call to install a USB device?>

Instance running effect:

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.