Mediator holds a class instance managed by Mediator in the field, and a class managed by Mediato holds an instance of Mediator and uses Mediator's method.
Mediator Gets the class status from the managed class instance and performs processing according to the status </ font>
Check with the following class structure
class | Explanation |
---|---|
Mediator.class | Hold an instance of the class you want to manage |
menber.class | men1.class~men2.class super Has a Mediator class chest |
user(Main.class) | Operation check |
Mediator.class
class Mediator{
menber men1 = new men1(),
men2 = new men2();
String check(menber menber){
if(menber.str == men1.str){return "men1";}
else{return "men2";}
}
}
menber.class
class menber{
Mediator mediator;
String str;
menber(String str){this.str =str;}
void set(){this.mediator=new Mediator();}
}
men.class
class men1 extends menber{ men1(){super("men1");}}
class men2 extends menber{ men2(){super("men2");}
user(Main.class)
public static void main(String[] args){
menber m1 = new men1();
m1.set();
String res = m1.mediator.check(m1);
System.out.println(res);
}
Recommended Posts