forked from jamalgithub/workdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExec.java
More file actions
47 lines (36 loc) · 1.2 KB
/
Exec.java
File metadata and controls
47 lines (36 loc) · 1.2 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
package observer;
/**
* Main Class
* @author Khalid Elshafie
* @created 9/13/17
*/
public class Exec {
public static void main(String[] args) {
//Instnace of the product
Product phone = new Product("Banana Phone");
//Person Observable
Person khalid = new Person("khalid");
Person sami = new Person("sami");
Person busrha = new Person("busrha");
//Company Observable
Company company = new Company("abolkog.com", "123 abc street");
//Add the observers
phone.addObserver(khalid);
phone.addObserver(sami);
phone.addObserver(busrha);
phone.addObserver(company);
//Simple loop
for(int i = 0; i < 5; i++) {
//Example of removing observer
if (i == 2) {
phone.removeObserver(sami);
}
//Set avaibality based on the i value (Just for demo)
boolean avaiable = i % 2 == 0;
phone.setAvailablity(avaiable);
//Simple delay for printing out the data.
try { Thread.sleep(1000); } catch (InterruptedException ie){}
System.out.println("--------------------------------");
}
}
}