Appearance mode-provides a unified interface for accessing a group of interfaces in a subsystem. The appearance defines a high-level interface to make the subsystem easier to use.
A look contains a lot of objects and operations on them, making it easier to repeat these operations.
If there is a light in the living room (Lights)
class Lights { publicvoid on () { Console.WriteLine ("Lights on " ); } Public void off () { Console.WriteLine ("Lights off"); } }
Television (TV)
class TV { publicvoid on () { Console.WriteLine ("TV -On " ); } Public void off () { Console.WriteLine ("TV off"); } }
and CD player (Dvdplaer)
classDvdplayer { Public voidOn () {Console.WriteLine ("DVD player on."); } Public voidoff () {Console.WriteLine ("DVD player off"); } Public voidPlay () {Console.WriteLine ("Start playing"); } Public voidEnd () {Console.WriteLine ("End End playing"); } }
You can define an appearance-cinema mode, which provides two ways to start watching a movie and ending a movie, respectively, for a series of actions.
classfacade {TV TV; Dvdplayer DVD; Lights Lights; Publicfacade (TV TV, Dvdplayer DVD, Lights Lights) { This. TV =TV; This. DVD =DVD; This. Lights =lights; } Public voidWatchmovie () {Console.WriteLine ("Get ready to watch a movie"); Lights.off (); Tv.on (); Dvd.on (); Dvd.play (); } Public voidEndmovie () {Console.WriteLine ("\nshutting movie theater down."); Lights.on (); Dvd.end (); Dvd.off (); Tv.off (); } }
This allows for a convenient one-click Cinema mode without having to ' personally ' operate a variety of devices each time.
class program { staticvoid Main (string[] args) { new TV (); New dvdplayer (); New Lights (); New facade (tv,dvd,lights); Facade.watchmovie (); Facade.endmovie (); Console.readkey (); } }
Output Result:
"Head First design mode" C # implementation (iii)--appearance mode