0

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?

3
  • 1
    What have you tried? Which methods are terminal, i.e. actually cause play to begin?
    – joshp
    Jan 16 '18 at 20:38
  • each function returns the class instance, terminal method is 'Play'..
    – meds
    Jan 17 '18 at 9:53
  • 1
    Something 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
    Jan 17 '18 at 16:40
10

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#.

1
  • 1
    obviously I know even less than I thought, thanks for the resources :)
    – meds
    Jan 16 '18 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.