Junior — Middle
Have you had experience using GPCT templates in your work?
sobes.tech AI
Answer from AI
The GPCT (General Purpose Command Template) is not widely known or standard in Java development. It might refer to something else, such as the Command pattern or design patterns related to command processing.
If we talk about the Command pattern, it is used to encapsulate a request as an object, allowing for parameterizing clients with different requests, queuing requests, logging them, and supporting undo operations.
Example of using the Command pattern in Java:
// Command interface
public interface Command {
void execute();
}
// Concrete command
public class LightOnCommand implements Command {
private Light light;
public LightOnCommand(Light light) {
this.light = light;
}
public void execute() {
light.on();
}
}
// Receiver
public class Light {
public void on() {
System.out.println("Light is ON");
}
}
// Client
public class RemoteControl {
private Command slot;
public void setCommand(Command command) {
slot = command;
}
public void buttonPressed() {
slot.execute();
}
}
If you meant a different pattern, please clarify.