Class CommandFactory
java.lang.Object
za.co.wethinkcode.robots.server.commands.CommandFactory
Factory responsible for constructing concrete
Command instances
from a parsed CommandRequest.
This class acts as the bridge between the transport layer and the
command layer. Incoming client requests are first deserialized into a
CommandRequest DTO, after which the factory determines the
appropriate concrete Command implementation to instantiate.
By centralising command creation, individual command implementations remain focused solely on business logic and are no longer responsible for parsing JSON or interpreting request payloads.
To add support for a new command:
- Create a new
Commandimplementation. - Add a corresponding case to the factory's
create()method.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandFactory(ClientID clientId) Creates a command factory associated with a specific client connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic Commandcreate(CommandRequest request) Creates the appropriate concreteCommandfrom a parsed client request.
-
Constructor Details
-
CommandFactory
Creates a command factory associated with a specific client connection.- Parameters:
clientId- the identifier of the client issuing commands
-
-
Method Details
-
create
Creates the appropriate concreteCommandfrom a parsed client request.The factory validates and converts request arguments where necessary before constructing the requested command.
- Parameters:
request- the parsed client request- Returns:
- the corresponding concrete
Command - Throws:
IllegalArgumentException- if the command is unknown or the supplied arguments are invalid
-