Java implementation appearance (facade) mode

Source: Internet
Author: User

/** * 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

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.