Java implementation Mediator (mediator) mode

Source: Internet
Author: User

Class diagram


Public interface Imediator {public void Createmediator ();p ublic void work ();

/** * Mediation, adjust the two elements that actually need to interact, let it loose coupling * @author stone * */public class mediator implements Imediator {private Xmlcode Xmlcode;priv Ate xmlpreview xmlpreview; @Overridepublic void Createmediator () {this.xmlcode = new Xmlcode (); this.xmlpreview = new XMLPR Eview ();} @Overridepublic void Work () {this.xmlCode.work (); This.xmlPreview.work ();}}
public interface IWork {void work ();}
/** * This class describes the preview interface in Android layout * Drag the component in the preview screen, the code will change * @author Stone * */public class Xmlpreview implements IWork {@Overridepubli c void Work () {System.out.println ("the component in the preview has changed");}}
/** * This class describes the XML code in the android layout * added code, the preview interface will change * @author Stone * */public class Xmlcode implements IWork {@Overridepublic Voi D work () {System.out.println ("Join layout Code");}}
/* Intermediary (Mediator) mode mediator means intermediaries, regulators, transitive objects, as the name implies, this pattern in the program will inevitably burden an intermediary, regulation, transfer of work * intermediaries so that each object does not need to explicitly reference each other, so that it is loosely coupled, and can independently change the interaction between them */public class Test {public static void main (string[] args) {imediator mediator = new Mediator (); mediator . Createmediator ();//create elements internally, maintain element mediator.work ();//work interface that executes internal elements}}

Print

Add component changes in the layout code preview



Java implementation Mediator (mediator) 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.