8. Bridging mode (bridge pattern)

Source: Internet
Author: User

usingSystem;namespaceconsoleapplication6{classProgram {Static voidMain (string[] args) {            //Create a remote controlRemotecontrol Remotecontrol =NewConcreteremote (); //Changhong TVRemotecontrol.implementor =NewChanghong ();            Remotecontrol.on ();            Remotecontrol.setchannel ();            Remotecontrol.off ();            Console.WriteLine (); //Samsung Brand TVRemotecontrol.implementor =NewSamsung ();            Remotecontrol.on ();            Remotecontrol.setchannel ();            Remotecontrol.off ();        Console.read (); }    }    /// <summary>    ///abstract concept of the remote control, playing the role of abstract/// </summary>     Public classRemotecontrol {//Field        PrivateTV implementor; //Properties         PublicTV implementor {Get{returnImplementor;} Set{implementor =value;} }        /// <summary>        ///turn on the TV, here the implementation is no longer provided in the abstract class, but the implementation in the implementation class is called/// </summary>         Public Virtual voidOn () {implementor.        On (); }        /// <summary>        ///turn off the TV/// </summary>         Public Virtual voidOff () {implementor.        Off (); }        /// <summary>        ///Change Channel/// </summary>         Public Virtual voidSetchannel () {Implementor.tunechannel (); }    }    /// <summary>    ///Specific Remote control/// </summary>     Public classConcreteremote:remotecontrol { Public Override voidSetchannel () {Console.WriteLine ("---------------------"); Base.            Setchannel (); Console.WriteLine ("---------------------"); }    }    /// <summary>    ///Television, providing an abstract approach/// </summary>     Public Abstract classTV { Public Abstract voidOn ();  Public Abstract voidOff ();  Public Abstract voidTunechannel (); }    /// <summary>    ///Changhong TV, overriding the abstract method of the base class///provide specific implementations/// </summary>     Public classCHANGHONG:TV { Public Override voidOn () {Console.WriteLine ("Changhong TV has been opened."); }         Public Override voidOff () {Console.WriteLine ("The Changhong TV has been turned off."); }         Public Override voidTunechannel () {Console.WriteLine ("Changhong TV Change channel"); }    }    /// <summary>    ///Samsung TV, overriding the abstract method of the base class/// </summary>     Public classSAMSUNG:TV { Public Override voidOn () {Console.WriteLine ("The Samsung TV is open."); }         Public Override voidOff () {Console.WriteLine ("The Samsung TV has been turned off."); }         Public Override voidTunechannel () {Console.WriteLine ("Samsung TV Change channel"); }    }}

8. Bridging mode (bridge pattern)

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.