/** * character * @author Stone * */public class Actor {public Actor (String name) {System.out.println ("Created role:" + name);} public void Load () {System.out.println ("role Loading");} public void Unload () {System.out.println ("role exits, archive");}}
/** * Scene * @author Stone * */public class Scene {public scene (String name) {System.out.println ("created scene:" + name);} public void Load () {System.out.println ("scene Load");} public void Unload () {System.out.println ("scene unload");}}
/** * Appearance class, which is a business function class, its implementation needs to hold other specific business objects * @author Stone * */public class facade {actor actor; Scene scene;public facade () {this.actor = new actor ("Lisi"), This.scene = new Scene ("Sea-sky Feast"); public void Startgame () {actor.load (); Scene.load ();} public void Endgame () {actor.unload (); Scene.unload ();}}
/** * Appearance (facade) mode * Simply to reduce the coupling between classes and classes, use a facade class to hold references to the original class. It is used in a very high frequency. * Similar to static proxy implementations, the difference is that the appearance pattern can hold multiple entity object references, to be combined to achieve business functions * @author Stone * */public class Test {public static void Main (string[] args) {/* * If you do not use the appearance mode, then at least one of the actor and scene may need to hold each other's references * when you need to add a new specific function class, simply add a reference in the facade and use it in the corresponding periodic function */ Facade facade = new facade (); Facade.startgame (); SYSTEM.OUT.PRINTLN ("----"); Facade.endgame ();}}
Print:
Created a role: Lisi created a scene: Sea-sky Feast role loading scene loading----role exit, archive scene unload
Java implementation appearance (facade) mode