I'm currently processing user input in client classes, however I feel that by doing this the command object's execute method I would be increasing the capability for reuse as one would only need to instantiate the command object to use its functionality rather than relying on the implementation from the client.
As a result, a command object may look like this:
public class CommandA implements Command {
ReceiverA receiverA;
public CommandA(RecieverA receiverA) {
this.receiverA = receiverA;
}
@Override
public void execute() {
Scanner scanner = new Scanner(System.in);
String x = scanner.nextLine();
receiverA.methodA(x);
}
}
I've found a lack of examples so I was wondering if this was a 'good' practice as in the examples I have seen a command object simply uses a method of a receiver.
Aucun commentaire:
Enregistrer un commentaire