-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton.java
More file actions
47 lines (37 loc) · 1.08 KB
/
Singleton.java
File metadata and controls
47 lines (37 loc) · 1.08 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
/**
* Singleton.java
*
* @author (your name)
* @version (a version number or a date)
*/
public class Singleton {
private static Singleton singleton = null;
private int state;
/** Creates a new instance of Singleton
* Declared private to prevent an instance being created other than using the getInstance method
*/
private Singleton() {
}
/**Static method getInstance is used to initialise the singleton object
*All calls to getInstance will return the same singleton object
*/
public static Singleton getInstance(){
if(singleton == null){
singleton = new Singleton();
}
return singleton;
}
/** The state field is provided to demonstrate that all Singleton references
* point to the same object
*/
public void setState(int state){
this.state = state;
}
public int getState(){
return state;
}
}
/*
*Source file generated by patternCoder for BlueJ Version 0.5.3.004.
*For more info, please visit http://www.patterncoder.org.
*/