[JAVA] Mediator Pattern

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>

Design Pattarm MENU

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
  • User Includes the meaning that other developers use this pattern

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

Mediator pattern
Mediator Pattern
Design pattern ~ Mediator ~
Prototype pattern
Memento Pattern
Iterator pattern
Composite pattern
Observer Pattern
Builder pattern
Bridge Pattern
Command Pattern
Builder Pattern
Iterator Pattern
Visitor pattern
Adapter Pattern
Proxy Pattern
Strategy Pattern
Composite Pattern
Singleton Pattern
Singleton pattern
Prototype Pattern
Facade Pattern
Flyweight Pattern
Decorator Pattern
Facade pattern
Visitor Pattern
Bridge pattern
abstract Factory Pattern
Design pattern ~ Builder ~
Design pattern ~ Visitor ~
Java design pattern
java callback pattern
Design pattern ~ Proxy ~
Design pattern ~ State ~
Factory Method Pattern
Design pattern ~ Strategy ~
Design pattern ~ Singleton ~
Design pattern ~ Composite ~
Design pattern (2): Builder
Design pattern (1): AbstractFactory
[Java] Singleton pattern
Design pattern ~ Command ~
Abstract Factory pattern
Design pattern ~ Iterator ~
Design pattern ~ Facade ~
Design pattern ~ Bridge ~
Template Method pattern
Design pattern ~ Decorator ~
Template Method Pattern
Design pattern ~ Interpreter ~
Factory Method pattern
Design pattern ~ Observer ~
Design pattern ~ Prototype ~
Design pattern ~ Memento ~
Design pattern ~ Adapter ~
Design pattern ~ Flyweight ~
Java pattern memo