Advertisement
Noah-Huppert

Singleton Question

Aug 25th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. /* Sample Singleton Class */
  2. public class Singleton {
  3.     public static Singleton singleton = null;
  4.  
  5.     protected Singleton(){}
  6.  
  7.     public static Singleton get(){
  8.         if(singleton == null){
  9.             singleton = new Singleton();
  10.         }
  11.         return singleton
  12.     }
  13.  
  14.     public boolean uselessFuction(){
  15.         return true;//Lets pretend this does something usefull
  16.     }
  17.  
  18.     /* HERE IS THE QUESTION */
  19.     /* Should I do this: */
  20.     public boolean loggedIn(){
  21.         boolean somethingUsefull = Singleton.get().uselessFunction();
  22.         return !somethingUsefull;
  23.     }
  24.  
  25.     /* OR this: */
  26.     public boolean loggedIn(){
  27.         boolean somethingUsefull = uselessFunction();
  28.         return !somethingUsefull;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement