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)