Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2. * -->This page is prepared by LordAmit
  3. */
  4. package observer.strategypattern;
  5.  
  6. /**
  7.  * A simple soldier class who has a name and can fight in different modes.
  8.  * @author LordAmit
  9.  */
  10. public class Soldier {
  11.     private String name;
  12.     private IMode solMode;
  13.  
  14.     /**
  15.      * constructor of soldier. It sets aggressive fighting mode by default
  16.      * @param name specifies the name of Soldier
  17.      * @since 2011
  18.      *
  19.      */
  20.  
  21.     public Soldier(String name) {
  22.         this.name = name;
  23.         solMode = new AggressiveFight();
  24.     }
  25.  
  26.     /**
  27.      * Sets the mode through Mode parameter implemented from IMode interface
  28.      * @since 2011
  29.      * @param mode sets the mode
  30.      */
  31.     public void setMode(IMode mode){
  32.         solMode = mode;
  33.     }
  34.  
  35.     /**
  36.      * Sets the soldier to fight in the mode specified through solMode
  37.      * @since 2011
  38.      */
  39.     public void fight(){
  40.         solMode.fight(this);
  41.     }
  42.     /**
  43.      *
  44.      * @return name of the soldier
  45.      * @since 2011 <br />
  46.      * by lordamit
  47.      */
  48.     public String getName() {
  49.         return name;
  50.     }
  51.  
  52. }