0
Answered

Doubt about Command pattern

John Dim 2 months ago updated by Alexander Shvets 2 months ago 2
In the very beginning of chapter Command, the book says 'Command is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This transformation lets you parameterize methods with different requests, delay or queue a request’s execution, and support undoable operations.', I'm confused with the expression 'This transformation lets you parameterize methods with different requests', why 'parameterize methods'?

Answered

Hi John!

Thanks for your question. I think I understand the reason for the confusion. This paragraph means that after wrapping the request in a command object, you can then pass this command object to any methods (on other objects) that deal with requests. Since all of the commands implement the same interface, you can pass different kinds of commands (and therefore, requests) to the said methods.

I'll see if I can rewrite this paragraph for a clearer understanding.

Okay, I've rewritten it like this:

**Command** is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This transformation lets you pass requests as a method arguments, delay or queue a request's execution, and support undoable operations.