-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton.java
More file actions
38 lines (28 loc) · 783 Bytes
/
Singleton.java
File metadata and controls
38 lines (28 loc) · 783 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
/**
*Singelton class create object of worm and enable to create once a time object after each eating.
* ---abstract factory design pattern----
* @author Adir Zoari 203002753
* @author Idan Levi 305562431
*/
public class Singleton {
private static Singleton instance = null;
/* A private Constructor prevents any other * class from instantiating.*/
/* Static 'instance' method */
public static Singleton getInstance(){
if (instance==null){
System.out.println("creating");
instance=new Singleton();
}
return instance;
}
//intialize the instance to null after the thread ate the instance - worm
public static void set(){
if(instance!=null){
instance=null;
}
}
public static Singleton get()
{
return Singleton.instance;
}
}