forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPresident.java
More file actions
31 lines (23 loc) · 807 Bytes
/
President.java
File metadata and controls
31 lines (23 loc) · 807 Bytes
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
package com.designpatterns.structural.proxy.president;
import com.designpatterns.creational.singleton.Singleton;
/**
* This is a class which is gonna be proxied by PresidentSecretary.
* Whenever any citizen decides to contact the President, they have to talk to the Secretary.
*/
public class President {
private volatile static President instance = null;
private President() {}
static President getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new President();
}
}
}
return instance;
}
void talkToThePresident(String message){
System.out.println("President: I have received the message:" + message);
}
}