ballwar.model.strategy
Class SwitcherStrategy

java.lang.Object
  extended by ballwar.model.strategy.SwitcherStrategy
All Implemented Interfaces:
IUpdateStrategy

public class SwitcherStrategy
extends Object
implements IUpdateStrategy

A Decorator design pattern strategy that decorates an IUpdateStrategy, enabling the strategy (the decoree) to be switched at run-time. All methods, except setStrategy() are delegated to the decoree.


Field Summary
private  IUpdateStrategy _strategy
           
 
Fields inherited from interface ballwar.model.IUpdateStrategy
NullObject
 
Constructor Summary
SwitcherStrategy()
           
 
Method Summary
 void init(Ball context)
          Initializes the context using the decoree strategy.
 void setStrategy(IUpdateStrategy newStrategy)
          Sets the decoree to reference the given strategy.
 void updateCollision(Ball context, Ball target)
          Processes the collision using the decoree.
 void updateKill(Ball context)
          Process the context's kill request using the decoree.
 void updateState(Ball context)
          Updates the state of the context using the decoree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_strategy

private IUpdateStrategy _strategy
Constructor Detail

SwitcherStrategy

public SwitcherStrategy()
Method Detail

init

public void init(Ball context)
Initializes the context using the decoree strategy.

Specified by:
init in interface IUpdateStrategy
Parameters:
context - The context for this and the decoree strategy.

updateState

public void updateState(Ball context)
Updates the state of the context using the decoree.

Specified by:
updateState in interface IUpdateStrategy
Parameters:
context - The context for this and the decoree strategy.

updateCollision

public void updateCollision(Ball context,
                            Ball target)
Processes the collision using the decoree.

Specified by:
updateCollision in interface IUpdateStrategy
Parameters:
context - The context for this and the decoree strategy.
target - The ball that the context with which the context has collided.

updateKill

public void updateKill(Ball context)
Process the context's kill request using the decoree.

Specified by:
updateKill in interface IUpdateStrategy
Parameters:
context - The context for this and the decoree strategy.

setStrategy

public void setStrategy(IUpdateStrategy newStrategy)
Sets the decoree to reference the given strategy.

Parameters:
newStrategy - The new decoree.