-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathObserver.cs
More file actions
42 lines (34 loc) · 909 Bytes
/
Observer.cs
File metadata and controls
42 lines (34 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BehavioralPatterns.Observer
{
public interface IObserver<T>
{
void Update(T data);
}
class CurrentConditionDisplay : IObserver<WeatherData>
{
private WeatherData data;
private string name;
public CurrentConditionDisplay(string name, WeatherData data)
{
this.name = name;
this.data = data;
data.addObserver(this);
Display();
}
public void Update(WeatherData data)
{
Console.WriteLine("Weather data is updated");
this.data = data;
Display();
}
private void Display()
{
Console.WriteLine("{0} - Temperature: {1}", this.name, this.data.Temperature);
}
}
}