forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
99 lines (81 loc) · 2.1 KB
/
Copy pathProduct.java
File metadata and controls
99 lines (81 loc) · 2.1 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.ArrayList;
public class Product implements Subject
{
private ArrayList<Observer> observers = new ArrayList<Observer>();
private String productName;
private String productType;
private String productPrice;
private String availability;
public Product( String productName, String productType, String productPrice, String availability )
{
super();
this.productName = productName;
this.productType = productType;
this.productPrice = productPrice;
this.availability = availability;
}
public ArrayList<Observer> getObservers()
{
return observers;
}
public void setObservers( ArrayList<Observer> observers )
{
this.observers = observers;
}
public String getProductName()
{
return productName;
}
public void setProductName( String productName )
{
this.productName = productName;
}
public String getProductType()
{
return productType;
}
public void setProductType( String productType )
{
this.productType = productType;
}
public String getProductPrice()
{
return productPrice;
}
public void setProductPrice( String productPrice )
{
this.productPrice = productPrice;
}
public String getAvailability()
{
return availability;
}
public void setAvailability( String availability )
{
this.availability = availability;
System.out.println("Availability changed from Not available to Available");
notifyObservers();
}
@Override
public void registerObserver( Observer observer )
{
observers.add(observer);
}
@Override
public void removeObserver( Observer observer )
{
observers.remove(observer);
}
@Override
public void notifyObservers()
{
System.out.println("Product Name :"
+ this.getProductName() + ", Product Type : " + this.productType + ", product Price : "
+ this.productPrice + " is available now.So notifying all the users ");
System.out.println();
for( Observer observer : observers )
{
observer.update(this.availability);
}
}
}