Skip to content

Commit 8ce0ffe

Browse files
committed
ggg
1 parent f48865b commit 8ce0ffe

File tree

1 file changed

+8
-2
lines changed
  • docs/document/Csharp Design Patterns/docs/Behavioural

1 file changed

+8
-2
lines changed

docs/document/Csharp Design Patterns/docs/Behavioural/Observer.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ The major downside of event in C# is **event leak**, which happens when event ha
120120

121121
.NET has builtin types to implement the same event mechanism with `System.IObserver<T>` and `System.IObservable<T>`
122122

123+
123124
```mermaid
124125
classDiagram
125126
class IObserver~T~ {
@@ -165,8 +166,13 @@ classDiagram
165166
PlayerEventArgs <|-- OnAttackEventArgs
166167
```
167168

168-
- `Subscribe` acts like `+=`
169-
- `Dispose` acts like `-=`
169+
**Observable and Observer do not know each other, the mediator is certain `EventArgs`. Observer handles notifications by different kinds of `EvntArgs`.**
170+
171+
- Observable: adds Observers
172+
- Subscription: as a `IDisposable` pair of Observer and Observable, will be stored on a collection inside Observable.
173+
- `Dispose` acts like `-=`
174+
- `Subscribe` acts like `+=`
175+
- Observer: independently handles different scenarios. `OnNext`, `OnError` .etc
170176

171177
```cs
172178
Player player = new() { Id = 1 };

0 commit comments

Comments
 (0)