I want to implement this singleton class in java . How can I put these variables in this class?
Asked
Active
Viewed 61 times
-9

ΦXocę 웃 Пepeúpa ツ
- 47,427
- 17
- 69
- 97

nourhan Elchiaty
- 1
- 1
-
1Welcome to Stack Overflow! Have you tried anything yet? – sp00m May 13 '17 at 11:21
-
Please try to implement a java class and if you have problems, come back. – guenhter May 13 '17 at 11:24
-
@guenhter i cant do it , i am beginner – nourhan Elchiaty May 13 '17 at 11:29
-
@sp00m I have made a singleton class but i dont know where to put these variables in this class – nourhan Elchiaty May 13 '17 at 11:33
-
https://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java?rq=1 – JHDev May 13 '17 at 11:33
-
Possible duplicate of [What is an efficient way to implement a singleton pattern in Java?](http://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java) – thewaywewere May 13 '17 at 16:30
1 Answers
0
This is one simple example for your singleton. Feel free to add setters and getters as you need it for the fields.
I'm not sure what the set
-method in your diagram should do but maybe you don't need it anyway.
public class LibraryInfo {
private static final LibraryInfo instance = new LibraryInfo();
public static LibraryInfo getInstance() {
return instance;
}
private LibraryInfo() {}
private String name;
private int phone;
private String address;
private String openTime;
private String closeTime;
// getters
}

guenhter
- 11,255
- 3
- 35
- 66