Last active
January 3, 2016 18:29
-
-
Save lexdene/8502247 to your computer and use it in GitHub Desktop.
single instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User{ | |
static public function instance(){ | |
static my_user = User() | |
return my_user; | |
} | |
public function setToken(token){ | |
this.token = token | |
} | |
public function getAvatar(){ | |
return this.avatar; | |
} | |
private token; | |
private avatar; | |
} | |
class LoginActivity{ | |
public function login_success(token){ | |
user = User.instance(); | |
user.setToken(token); | |
} | |
} | |
class MainActivity{ | |
public function onupdate(){ | |
user = User.instance(); | |
avatar_widget = this.avatar(); | |
avatar_widget.setImage(user.getAvatar()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment