Bridging Mode-

Source: Internet
Author: User

<?PHP//Basic classes of Zergclasszerg{//basic objects for implementing a drill ground     Public $imp; //a method for switching the base object of the drill ground     Public functionSetimp ($imp)    {        $this->imp =$imp;//$this->imp receives a specific object under an instantiated Implementor interface    }    //The drill Ground method of the force, which extends the ground of the base object     Public functionUnderground () {$this->imp->underground ();//this underground () method from the Implementor interface    }}//Puppy 's classclassZerglingextendszerg{/*call the basic drilling method, and then implement the extension, here the simple echo this method is very flexible, in addition to the implementation of the function here, but also to inherit the parent class method, and, what is implemented in this method of the parent class, is passed by another object-method .*/     Public functionUnderground () {Parent::Underground (); Echo' Now stab the ground, and the puppy will not move <br> '; }}//the class of the ground thornclassLurkerextendszerg{//call the basic drill-down method and then implement the extension, where the simple echo     Public functionUnderground () {Parent::Underground (); Echo' Now stab the ground and be able to attack <br> '; }}//basic interface of drilling groundInterfaceimplementor{//Basic method of drilling ground     Public functionUnderground ();}//Basic classes of stealth drilling groundclassInvisibleimpImplementsimplementor{//Basic method of drilling ground     Public functionUnderground () {Echo' Drill ground, invisible <br> '; }}//A basic class of non-stealth drilling, such as what the player sees or is detected .classVisibleimpImplementsimplementor{//Basic method of drilling ground     Public functionUnderground () {Echo' Drill ground, visible <br> '; }}/*Test*/$z 1=NewZergling ();//build a puppy.$z 1->setimp (NewInvisibleimp ());//The Puppy drill ground function is set by the drill ground class in the puppy's parent class, and is inherited in the puppy drill local law$z 1->underground ();//the Underground () here is the method in the Zergling classEcho' ;$l 1=NewLurker ();//Build a ground thorn$l 1->setimp (Newinvisibleimp ());$l 1-Underground ();Echo' ;$l 1->setimp (NewVisibleimp ());//The enemy is in a hurry, fly over to a tech ball, view stealth objects$l 1->underground ();//The enemy saw the Thorn, the ground Thorn continued to attack the enemy?>

Usage Summary: Bridging mode separates the basic implementation from the specific invocation class, and the calling class can extend the more complex implementation.

Implementation summary: Some basic execution classes are required to implement the basic methods, such as the above two drill ground classes. At the same time we can design a number of different extension call classes, the basic functions of extension, such as the Thorn and puppy to further realize the different underground behavior.

Bridging Mode-

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.