Chapter 24. Command
The ordinary way to cause a method to execute is to call it. There may be times, though, when you cannot control the timing of or the context in which a method should execute. In these situations, you can encapsulate a method inside an object. By storing the information necessary for invoking a method in an object, you can pass the method as a parameter, allowing a client or service to determine when to invoke the method.
Fortunately, delegates in C# expressly support the ability to encapsulate a method in an object. However, this is a good example of how language support does not eliminate the role of patterns. Although C# provides direct support for the COMMAND pattern, developers must still understand how to employ the purpose ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access