Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:37:35+00:00 2026-05-22T14:37:35+00:00

Having seen how Command pattern was used in a previous project, I can understand

  • 0

Having seen how Command pattern 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.

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.

Is my understanding of this limitation correct? On the contrary, is it possible to run decorator on multiple threads?


What I’m trying to implement is a pipeline that processes a stream of data.

  • To implement as Command pattern, its execute method would take two arguments: a buffer for input and a buffer for output.
  • To implement as Decorator pattern, its getdata method would call its delegate to get the result of the previous step, apply its own processing, and return the result to the caller.

However after I have implemented it in both styles, I found that each has limitations that wasn’t clear to me originally.

  • 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.
  • 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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:37:36+00:00Added an answer on May 22, 2026 at 2:37 pm

    Whether you can run Decorators on any thread is implementation defined 🙂

    If your decorators are thread safe… yes. If not: add synchronisation. This might undermine your performance.

    However, in my view, it makes a lot of sense for decorators to mostly occupy themselves with the object they are decorating, and only little bits of context/state outside that. The object being decorated here, obviously should be threadsafe (or aware) in the first place, or it would have the same problem even without the decorator.

    Perhaps this is what you call ‘lightweight’ decorators. If your decorators are heavyweight (in that they ‘use the world’ to do their job) there’s definitely going to be synchronisation required. This may even lead to performance bottlenecks.

    But fundamentally nothing precludes a (in general) decorator from being executed on any thread you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen new computers having two processors on same motherboard . How can
Having seen the advantages of metaprogramming in Ruby and Python, but being bound to
Problem with arithmetic using logarithms to avoid numerical underflow (take 2) Having seen the
I have seen source codes always having a typedef for a structure and using
I have seen on the web some domain names having prefix of ww2 or
I've seen a fair share of ungainly XML->JSON code on the web, and having
I've seen alot of tutorials on search with php and mysql, but im having
We have all seen countless instances of forms with a select drop down having
Does PHP have a method of having auto-generated class variables? I think I've seen
A small - little question. I have seen many application having buttons like following.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.