Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSlowvomit

Posted 13 September 2013 - 07:29 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
        //game initialize phase:
        //constructing the objects in our game
        GameObject[] movingObjects = new GameObject[10]; 
        for(int i = 0; i < movingObjects.Length; i++)
        {
            movingObjects[i] = new movingObject();
            movingObjects[i].SetMoveStrategy(new BasicMovement());
        }
        //set object 1 to use astar
        movingObjets[1].SetMoveStrategy(new AStarMovement);
 
        //game update phase:
        //showcasing polymorphysism
        //we don't care which movement algorithm is selected for the game objects we simply want them all to move.
        for(int i = 0; i < movingObjects.Length; i++)
        {
             movingObject.Move(MovementType.Walk);
        }
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MovementStrategy movementStrategy;
 
    public void SetMoveStrategy(MovementStrategy movementStrategy)
    {
         this.movementStrategy = movementStrategy;
    }
 
    public void Move(MovementType movementType)
    {
         movementStrategy.Move(movementType);
    }
}
 
public enum MovementType
{
    Skip,
    Walk,
    Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
        //Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

#6Slowvomit

Posted 13 September 2013 - 06:20 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
        //game initialize phase:
        //constructing the objects in our game
        GameObject[] movingObjects = new GameObject[10]; 
        for(int i = 0; i < movingObjects.Length; i++)
        {
            movingObjects[i] = new movingObject();
            movingObjects[i].SetMoveStrategy(new BasicMovement());
        }
        //set object 1 to use astar
        movingObjets[1].SetMoveStrategy(new AStarMovement);
 
        //game update phase:
        //showcasing polymorphysism
        //we don't care which movement algorithm is selected for the game objects we simply want them all to move.
        for(int i = 0; i < movingObjects.Length; i++)
        {
             movingObject.Move(MovementType.Walk);
        }
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MovementStrategy movementStrategy;
 
    public void SetMoveStrategy(MovementStrategy movementStrategy)
    {
         this.movementStrategy = movementStrategy;
    }
 
    public void Move(MovementType movementType)
    {
         moveStrategy.Move(movementType);
    }
}
 
public enum MovementType
{
    Skip,
    Walk,
    Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
        //Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : SortStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

#5Slowvomit

Posted 13 September 2013 - 06:19 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
        //game initialize phase:
        //constructing the objects in our game
        GameObject[] movingObjects = new GameObject[10]; 
        for(int i = 0; i < movingObjects.Length; i++)
        {
            movingObjects[i] = new movingObject();
            movingObjects[i].SetMoveStrategy(new BasicMovement());
        }
        //set object 1 to use astar
        movingObjets[1].SetMoveStrategy(new AStarMovement);
 
        //game update phase:
        //showcasing polymorphysism
        //we don't care which movement algorithm is selected for the game objects we simply want them all to move.
        for(int i = 0; i < movingObjects.Length; i++)
        {
             movingObject.Move(MovementType.Walk);
        }
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MoveStrategy moveStrategy;
 
    public void SetMoveStrategy(MovementStrategy moveStrategy)
    {
         this.moveStrategy = moveStrategy;
    }
 
    public void Move(MovementType movementType)
    {
         moveStrategy.Move(movementType);
    }
}
 
public enum MovementType
{
    Skip,
    Walk,
    Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
        //Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : SortStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

#4Slowvomit

Posted 13 September 2013 - 06:13 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
        //game initialize phase:
        //constructing the objects in our game
        GameObject[] movingObjects = new GameObject[10]; 
        for(int i = 0; i < movingObjects.Length; i++)
        {
            movingObjects[i] = new movingObject();
            movingObjects[i].SetMoveStrategy(new BasicMovement());
        }
        //set object 1 to use astar
        movingObjets[1].SetMoveStrategy(new AStarMovement);
 
        //game update phase:
        //showcasing polymorphysism
        //we don't care which movement algorithm is selected for the game objects we simply want them all to move.
        for(int i = 0; i < movingObjects.Length; i++)
        {
             movingObject.Move(MoveType.Walk);
        }
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MoveStrategy moveStrategy;
 
    public void SetMoveStrategy(MoveStrategy moveStrategy)
    {
         this.moveStrategy = moveStrategy;
    }
 
    public void Move(MovementType movementType)
    {
         moveStrategy.Move(moveStrategy);
    }
}
 
public enum MovementType
{
    Skip,
    Walk,
    Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
        //Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : SortStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
         //A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

#3Slowvomit

Posted 13 September 2013 - 06:08 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
//game initialize phase:
//constructing the objects in our game
GameObject[] movingObjects = new GameObject[10]; 
for(int i = 0; i < movingObjects.Length; i++)
{
movingObjects[i] = new movingObject();
movingObjects[i].SetMoveStrategy(new BasicMovement());
}
//set object 1 to use astar
movingObjets[1].SetMoveStrategy(new AStarMovement);
 
//game update phase:
//showcasing polymorphysism
//we don't care which movement algorithm is selected for the game objects [font='Helvetica Neue', Arial, Verdana, sans-serif]we simply want them all to move.[/font]
for(int i = 0; i < movingObjects.Length; i++)
{
movingObject.Move(MoveType.Walk);
}
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MoveStrategy moveStrategy;
 
    public void SetMoveStrategy(MoveStrategy moveStrategy)
    {
this.moveStrategy = moveStrategy;
    }
 
    public void Move(MovementType movementType)
    {
moveStrategy.Move(moveStrategy);
    }
}
 
public enum MovementType
{
Skip,
Walk,
Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : SortStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

#2Slowvomit

Posted 13 September 2013 - 06:07 PM

I understand that its a arbitrary example to learn the strategy pattern. But it is not aptly applied. The strategy pattern is a way to encapsulate algorithms and make them easily interchangeable. You would never use a design pattern for something as trivial as movement speed and animation change.
Movement can however be aptly applied to a strategy pattern example using your movement types:
public class Program
{
    public static void Main()
    {
//game initialize phase:
//constructing the objects in our game
GameObject[] movingObjects = new GameObject[10]; 
for(int i = 0; i < movingObjects.Length; i++)
{
movingObjects[i] = new movingObject();
movingObjects[i].SetMoveStrategy(new BasicMovement());
}
//set object 1 to use astar
movingObjets[1].[font='Helvetica Neue', Arial, Verdana, sans-serif]SetMoveStrategy(new AStarMovement);[/font]
 
//game update phase:
//showcasing polymorphysism
//we don't care which movement algorithm is selected for the game objects [font='Helvetica Neue', Arial, Verdana, sans-serif]we simply want them all to move.[/font]
for(int i = 0; i < movingObjects.Length; i++)
{
movingObject.Move(MoveType.Walk);
}
    }
}
 
public class GameObject //context of strategy pattern
{ 
    private MoveStrategy moveStrategy;
 
    public void SetMoveStrategy(MoveStrategy moveStrategy)
    {
this.moveStrategy = moveStrategy;
    }
 
    public void Move(MovementType movementType)
    {
moveStrategy.Move(moveStrategy);
    }
}
 
public enum MovementType
{
Skip,
Walk,
Run
}
 
public abstract class MovementStrategy //interface of strategy pattern
{
    public abstract void Move();
}
 
public class BasicMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//Basic Movement algorithm here, differentiate by movement type.
    }
}
 
public class BreadCrumbMovement : MovementStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//Bread Crumb algorithm here, differentiate by movement type.
    }
}
 
public class AStarMovement : SortStrategy //concrete strategy
{
    public override void Move(MovementType movementType)
    {
//A Star algorithm here, differentiate by movement type.
    }
}
 
The base keyword is not used at all to demonstrate the strategy pattern. It is used for "inheriting" constructor arguments passed to the base class or to reference it implicitly.

PARTNERS