Note that there are some explanatory texts on larger screens.

plurals
  1. POTo use multithreading, is Command pattern more useful than Decorator pattern?
    primarykey
    data
    text
    <p>Having seen how <a href="http://en.wikipedia.org/wiki/Command_pattern" rel="nofollow">Command pattern</a> was used in a previous project, I can understand how it can be useful in multithreaded (parallel) programming, because Commands can be executed in different threads. When data needs to be passed between commands, the data can be stored in a shared memory and a pointer (or handle) to that data can be passed to an invoker on a differeht thread.</p> <p>However, Decorator pattern seems to have the restriction that everything must happen on a single thread, because the decorator has to call the delegate directly, implying they must be on the same thread.</p> <p>Is my understanding of this limitation correct? On the contrary, is it possible to run decorator on multiple threads?</p> <hr> <p>What I'm trying to implement is a pipeline that processes a stream of data.</p> <ul> <li>To implement as Command pattern, its <code>execute</code> method would take two arguments: a buffer for input and a buffer for output.</li> <li>To implement as Decorator pattern, its <code>getdata</code> method would call its delegate to get the result of the previous step, apply its own processing, and return the result to the caller.</li> </ul> <p>However after I have implemented it in both styles, I found that each has limitations that wasn't clear to me originally.</p> <ul> <li>When using the Command pattern, I can start accepting more input data by using a new buffer, while the earlier buffers are being processed by some Commands running in separate work threads. I can't seem to do this with Decorator pattern.</li> <li>When using the Decorator pattern, the decorator can make any number of calls to its delegate and be able to combine the results into one chunk. It can also split data, by making one big request, cache it, and then returning pieces of it. When I use Command pattern with one input buffer and one output buffer, there cannot be any combination or splitting of results.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload