Chapter 21. COMMAND and ACTIVE OBJECT: Versatility and Multitasking


Chapter 21. COMMAND and ACTIVE OBJECT: Versatility and Multitasking

© Jennifer M. Kohnke

No man has received from nature the right to command his fellow human beings.

Denis Diderot (17131784)

Of all the design patterns that have been described over the years, COMMAND impresses me as one of the simplest and most elegant. But we shall see, the simplicity is deceptive. The range of uses that COMMAND may be put to is probably without bound.

The simplicity of COMMAND, as shown in Figure 21-1, is almost laughable. Listing 21-1 doesn't do much to dampen the levity. It seems absurd that we can have a pattern that consists of nothing more than an interface with one method.

Figure 21-1. COMMAND pattern


Listing 21-1. Command.cs

public interface Command {   void Execute(); }

In fact, this pattern has crossed a very interesting line. And it is in the crossing of this line that all the interesting complexity lies. Most classes associate a suite of methods with a corresponding set of variables. The COMMAND pattern does not do this. Rather, it encapsulates a single function free of any variables.

In strict object-oriented terms, this is anathema, smacking of functional decomposition. It elevates the role of a function to the level of a class. Blasphemy! Yet at this boundary where two paradigms clash, interesting things start to occur.




Agile Principles, Patterns, and Practices in C#
Agile Principles, Patterns, and Practices in C#
ISBN: 0131857258
EAN: 2147483647
Year: 2006
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net