Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove this circular dependency

I am currently trying to design a piece of screen-capture software.

One design question I am having is I want to know if it is possible to eliminate the circular dependency between the PictureGetter and the PictureProcessor.

The getter needs to call the processor to tell it that a picture is ready. The processor has to tell the getter that it is done processing the picture.

These two elements are in separate threads and cannot share data directly(and I do not want to share data), they can only add member calls of the target object onto that object's queue queue. (eg queue.add(&PictureProccessor::sendPicture,picture) )

enter image description here


1 Answers

Use a resource manager, make both aware of that. The getter can enqueue a picture to be processed with the manager, the manager can then have a "pool" of processors of which one can be used for processing. Processor can enqueue the processed picture with the resource manager which can then notify to the appropriate getter. I'm sure there's some funky name for this pattern, but cannot recall it right now.

like image 186
Nim Avatar answered Aug 21 '26 11:08

Nim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!