mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 21:34:06 -06:00
19 lines
468 B
Markdown
19 lines
468 B
Markdown
#cs240
|
|
When you want to have only one instance of an object in all of your code, you define its constructor as private, and create a public static getInstance method.
|
|
The *single* instance is put into a private static variable.
|
|
|
|
public class DataCache {
|
|
private static DataCache instance;
|
|
|
|
public static DataCache getInstance() {
|
|
if(instance == null) {
|
|
instance = new DataCache();
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
private DataCache(){
|
|
|
|
}
|
|
} |