java - Design Pattern - Single Object can only exist in single Event -


i'm looking suitable design pattern small game.

  • a player can exist in single event
  • but player can added(exist) in new event long old event terminated == true

what design pattern suit scenario? current setup make sense?

public class player  {     public int id;       public player(int id) {         this.id = id;     } }   public class event   {     public list<player> allplayer = new arraylist<player>();         public boolean terminated = false;     public event(){}             public void addplayer(player player){         allplayer.add(player);     }        }  public class battle extends event {     public battle(){}    }  public class training extends event {         public training(){} } 

you can delegate event player , when event terminates, can use terminated flag determine if able associate player event.

public class player {     private event event;      private int id;      ...      public void setevent(event event) throws exception {         if (!this.event.terminated) {             throw new exception("player has event associated with");         } else {             this.event = event;         }      } } 

note there other ways notify player event has been terminated.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -