in my application I've got three interfaces ICapture<T>
, IDecoder<T, K>
, and IBroadcaster<K>
.
Now I implement for example a VideoCapture
class inheriting from Capture<IntPtr>
(IntPtr is the raw data produced by the class). When data is generated by an object of VideoCapture
, I firstly want to decode it from T
to K
, and then broadcast it.
What I want to know is: how would you chain this ? Simply by writing a method like
var data = videoCapture.GetData();
var decoded = decoder.Decode(data);
broadcaster.Broadcast(decoded);
Or are there any design patterns, that I could use? I know of the chain of responsibility pattern. I could imagine writing classes like CaptureHandler
, DecoderHandler
, and BroadcastHandler
inheriting from HandlerBase
. HandlerBase
would provide mechanisms to hand over objects to the next handler.
var handler1 = new CaptureHandler();
var handler2 = new DecodeHandler();
handler1.SetNext(handler2);
handler1.Handle(object);
But I dunno if this is the best approach for my situation.
Why would you want to avoid the method? It's simple, and I see no disadvantage for your application.
If the GetData
=> Decode
=> Broadcast
pattern is useful for other captures, you can make the method generic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With