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: