Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object manipulation chaining

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.

like image 499
Matthias Avatar asked Oct 10 '22 12:10

Matthias


1 Answers

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.

like image 79
CodesInChaos Avatar answered Oct 13 '22 10:10

CodesInChaos