-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediatorTest.java
More file actions
57 lines (49 loc) · 1.47 KB
/
MediatorTest.java
File metadata and controls
57 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package tests.behavioural;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import patterns.behavioural.mediator.Government;
import patterns.behavioural.mediator.Mediator;
import patterns.behavioural.mediator.Scientist;
/**
* MEDIATOR PATTERN
*
* <p>Purpose: Centralizes communication between components, reducing direct connections and dependencies.
*
* <p>When to use:
* <ul>
* <li>When a set of objects communicate in well-defined but complex ways</li>
* <li>When reusing an object is challenging because it communicates with many other objects</li>
* </ul>
*
* <p>Common Pitfalls:
* <ul>
* <li>Creating a mediator that becomes a "god object"</li>
* <li>Not properly defining the communication protocol</li>
* </ul>
*/
class MediatorTest {
/**
* We need a way to ensure the scientific discoveries we make are shared with the world.
*
* <p>Use the mediator pattern to create a framework to share scientific discoveries
*/
@Test
void example() {
var mediator = new Mediator();
var humboldt = new Scientist(mediator, "Humboldt");
var bmd = new Government(mediator, "BMD");
mediator.send("[NEW DATA]");
humboldt.send("We have made a discovery!");
bmd.send("We are interested in your discovery.");
}
@Test
@Disabled
void todo() {
/*
* todo:
* add a another institution
* expand the pattern to filter by institution type
* add support for private messaging
* */
}
}