Advantages of .NET Rx over classic events?

前端 未结 4 470
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 16:24

.NET 4.0 beta 2 has introduced the IObservable and IObserver interfaces.

What are the advantages compared to classic .NET events? Doesn\'t this solve the same problem?<

4条回答
  •  孤街浪徒
    2021-02-01 17:21

    It's just an extension to the event based programming model. You create something that implements IObserver, and basically you're saying "here's what I want to happen when something in the collection changes". In that way, it's just a standardization of what we've all been doing with events.

    They're pushing it like it's a big about-face compared with the IEnumerable pattern. IEnumerable is "pull", whereas IObservable is "push".

    The only advantage I see over straight events is that it's a standardized interface. I see a big overlap with ObservableCollection here though (and INotifyCollectionChanged). Maybe they're trying to adopt the PERL motto with .NET: "there's more than one way to do it".

提交回复
热议问题