假设我有两个类,您可以在其中观察一些可观察值。第一个例子,带有公共(public)主题:classEventsPub{publicreadonlyonEnd=newSubject();}第二个例子,私有(private)主题和注册方法:classEventsPriv{privatereadonlyendEvent=newSubject();publiconEnd(cb:()=>void):Subscription{returnthis.endEvent.subscribe(cb);}}第一个示例在某种程度上是不安全的,因为任何人都可以从类外部调用eventsPub.endEvent.n