lundi 8 mai 2017

About colleague in mediator design pattern?

I know the purpose of mediator pattern is that each colleague don't have to know each other to communicate with each other. All colleagues just know about the mediator.

Design patterns are not for specific language, but my question is specific to Java.

  • In Java, all fields in interface are public static final, and it's also not a good practice to use such fields.
  • But each colleague need to keep a reference to the mediator, and if the field is final then each colleague can't change the mediator in the runtime.
  • As the structure below, the colleague is an abstract class instead. But multiple inheritance is not allow in Java. Then this pattern would not be useful since the concrete colleague may already inherit some other class.

So I want to know:

  1. If each colleague don't keep a reference to the mediator, it can still be a mediator pattern?(For me the answer is yes) Will this change cause any problem?
  2. If I want to keep a reference for each colleague, and implement the pattern in Java, how could it be done?

The structure of mediator pattern: Mediator pattern from http://ift.tt/2pTz89j

Aucun commentaire:

Enregistrer un commentaire