strategy-theory.cs

strategy-theory.cs - using System; / Strategy Pattern by...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1  using System // Strategy Pattern by Judith Bishop Oct 2007 // Shows two strategies and a random switch between them // The Context class Context { // Context state public const int start = 5 public int Counter = 5 // Strategy aggregation IStrategy strategy = new Strategy1() // Algorithm invokes a strategy method public int Algorithm() { return strategy.Move(this) } // Changing strategies public void SwitchStrategy() { if (strategy is Strategy1) strategy = new Strategy2() else strategy = new Strategy1() } } // Strategy interface interface IStrategy { int Move (Context c) } // Strategy 1 class Strategy1 : IStrategy {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

strategy-theory.cs - using System; / Strategy Pattern by...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online