I've been using Linq for a while unknowingly that it uses a Reactive pattern that I'm quite fond of.
I'd like to roll my own function in that pattern but wasn't sure if it's appropriate and also wanted to throw out ideas about how I would do it.
My goal is to make a video player service that is injecte dinto classes, the service contains a function which plays a video but the user can do other things, something like:
videoPlayer.Play(videoClip).StartAt(3).EndAt(8).OnUpdate((event)=>{}).Finish((event)=>{})
Does this make sense for reactive programming and how would I go about implementing it in C#? My thought was videoPlayer.Play returns a class with all the functions such as StartAt and EndAt which in turn return the same class object.
Would that be the way to do it?
-
1What have you tried? Which methods are terminal, i.e. actually cause play to begin?joshp– joshp2018年01月16日 20:38:16 +00:00Commented Jan 16, 2018 at 20:38
-
each function returns the class instance, terminal method is 'Play'..meds– meds2018年01月17日 09:53:47 +00:00Commented Jan 17, 2018 at 9:53
-
1Something like videoPlayer.clip(videoClip).startAt(3).endAt(8).onUpdate(blah).play() should work, with each non-terminal function returning videoPlayer, and play() actually doing the playing.joshp– joshp2018年01月17日 16:40:42 +00:00Commented Jan 17, 2018 at 16:40
1 Answer 1
That is not reactive programming. Reactive programming is something entirely different.
What you have is called fluent interface. And it is quite trivial to implement in C#.
-
1obviously I know even less than I thought, thanks for the resources :)meds– meds2018年01月16日 13:38:56 +00:00Commented Jan 16, 2018 at 13:38