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