Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 19 design patterns Obvious three argument constructor not shown The intent is that the main program BidPaySite doesnt need to know or care what the clients are sending it As long as the objects implement Command it will be happy and the Auction class will receive whats sent and process it public class BidPaySite public void submitCommand Command command These could go into a queue to serialize them or you could make sure that all methods exposed to the Command are thread safe For now just let the command do its thing command execute There are times when you want multiple commands to execute as a single command for example something like database transactions or batching or reducing network trafic on a remote connection You could create a CompositeCommand which is created with an array or List of commands The execute method of a List implementation could be something like this class CompositeCommand implements Command List Command commands public void execute commands forEach Command execute Obvious one argument constructor omitted
You must have JavaScript enabled to view digital editions.