-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonOnOrder.java
More file actions
42 lines (35 loc) · 862 Bytes
/
AmazonOnOrder.java
File metadata and controls
42 lines (35 loc) · 862 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
32
33
34
35
36
37
38
39
40
41
42
package DesignPatterns.ObserverDesignPattern;
import java.util.ArrayList;
public class AmazonOnOrder {
public static AmazonOnOrder instance=null;
public ArrayList<AmazonOnOrderNotify> list=new ArrayList<>();
public void register(AmazonOnOrderNotify az)
{
list.add(az);
}
public void deregister(AmazonOnOrderNotify az)
{
list.remove(az);
}
public static AmazonOnOrder getInstance()
{
if(instance==null)
{
synchronized(AmazonOnOrder.class)
{
if (instance==null)
{
instance= new AmazonOnOrder();
}
}
}
return instance;
}
public void onOrderPlaced()
{
for(AmazonOnOrderNotify az: list)
{
az.notifyOrder();
}
}
}