summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo_khan <mo@mokhan.ca>2009-05-24 20:21:24 -0600
committermo_khan <mo@mokhan.ca>2009-05-24 20:21:24 -0600
commit8c03ead6541f944a91d71d7e0c8c7ea2b8df904b (patch)
treec9006b7322320c3ae6aac589a90011475db93fad
parent14e97ee3a202ad59bba6feec225f9f0410b4f61a (diff)
refactoring command pump
-rw-r--r--product/project/presentation/CaptureUserInstructionsPresenter.cs10
-rw-r--r--product/project/presentation/infrastructure/CommandPump.cs4
-rw-r--r--product/project/presentation/infrastructure/SynchronousCommandPump.cs32
3 files changed, 31 insertions, 15 deletions
diff --git a/product/project/presentation/CaptureUserInstructionsPresenter.cs b/product/project/presentation/CaptureUserInstructionsPresenter.cs
index b60e11d..3f2fcf1 100644
--- a/product/project/presentation/CaptureUserInstructionsPresenter.cs
+++ b/product/project/presentation/CaptureUserInstructionsPresenter.cs
@@ -5,9 +5,9 @@ namespace mars.rover.presentation
public class CaptureUserInstructionsPresenter : Presenter
{
readonly CaptureUserInstructionsView view;
- readonly CommandPump<string> pump;
+ readonly CommandPump pump;
- public CaptureUserInstructionsPresenter(CaptureUserInstructionsView view, CommandPump<string> pump)
+ public CaptureUserInstructionsPresenter(CaptureUserInstructionsView view, CommandPump pump)
{
this.view = view;
this.pump = pump;
@@ -20,17 +20,17 @@ namespace mars.rover.presentation
public virtual void provide_upper_right_coordinates(string line)
{
- pump.run<CreateMarsCommand>(line);
+ pump.run<CreateMarsCommand, string>(line);
}
public virtual void deploy_rover_to(string deployment_coordinates)
{
- pump.run<DeployRoverCommand>(deployment_coordinates);
+ pump.run<DeployRoverCommand, string>(deployment_coordinates);
}
public virtual void navigate_rover_using(string navigation_commands)
{
- pump.run<NavigateRoverCommand>(navigation_commands);
+ pump.run<NavigateRoverCommand, string>(navigation_commands);
}
public void go()
diff --git a/product/project/presentation/infrastructure/CommandPump.cs b/product/project/presentation/infrastructure/CommandPump.cs
index 3bf6f28..a998234 100644
--- a/product/project/presentation/infrastructure/CommandPump.cs
+++ b/product/project/presentation/infrastructure/CommandPump.cs
@@ -2,8 +2,8 @@ using mars.rover.common;
namespace mars.rover.presentation.infrastructure
{
- public interface CommandPump<Input> : Command
+ public interface CommandPump : Command
{
- void run<Command>(Input input) where Command : ParameterizedCommand<Input>;
+ void run<Command, Input>(Input input) where Command : ParameterizedCommand<Input>;
}
} \ No newline at end of file
diff --git a/product/project/presentation/infrastructure/SynchronousCommandPump.cs b/product/project/presentation/infrastructure/SynchronousCommandPump.cs
index 294ac9b..7c197ea 100644
--- a/product/project/presentation/infrastructure/SynchronousCommandPump.cs
+++ b/product/project/presentation/infrastructure/SynchronousCommandPump.cs
@@ -3,32 +3,48 @@ using mars.rover.common;
namespace mars.rover.presentation.infrastructure
{
- public class SynchronousCommandPump : CommandPump<string>
+ public class SynchronousCommandPump : CommandPump
{
readonly Registry<ParameterizedCommand<string>> commands;
readonly CommandProcessor processor;
readonly CommandFactory factory;
- public SynchronousCommandPump(Registry<ParameterizedCommand<string>> commands, CommandProcessor processor, CommandFactory factory)
+ public SynchronousCommandPump(Registry<ParameterizedCommand<string>> commands, CommandProcessor processor,
+ CommandFactory factory)
{
this.commands = commands;
this.processor = processor;
this.factory = factory;
}
- public virtual void run<Command>(string input) where Command : ParameterizedCommand<string>
+ public virtual void run<Command, Input>(Input input) where Command : ParameterizedCommand<Input>
{
- processor.add(factory.create_for(() => get<Command>().run_against(input)));
+ processor.add(factory.create_for(() => get<Command, Input>().run_against(input)));
}
- ParameterizedCommand<string> get<T>()
+ public virtual void run()
{
- return commands.First(y => y is T);
+ processor.run();
}
- public virtual void run()
+ ParameterizedCommand<Input> get<Command, Input>()
{
- processor.run();
+ return new AdaptedCommand<Input>(commands.First(y => y is Command));
+ }
+
+ class AdaptedCommand<T> : ParameterizedCommand<T>
+ {
+ readonly ParameterizedCommand<string> command;
+
+ public AdaptedCommand(ParameterizedCommand<string> command)
+ {
+ this.command = command;
+ }
+
+ public void run_against(T item)
+ {
+ command.run_against(item as string);
+ }
}
}
} \ No newline at end of file