Skip to content

Instantly share code, notes, and snippets.

@lexdene
Last active January 3, 2016 18:29
Show Gist options
  • Save lexdene/8502247 to your computer and use it in GitHub Desktop.
Save lexdene/8502247 to your computer and use it in GitHub Desktop.
single instance
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