Update Observer pattern
This commit is contained in:
@@ -8,16 +8,25 @@ namespace ObserverPattern.Twits
|
||||
/// <summary>
|
||||
/// Concrete observer
|
||||
/// </summary>
|
||||
public class TwitUser : IObserver<string>
|
||||
public class TwitUser : IObserver<Twit>, IDisposable
|
||||
{
|
||||
string name;
|
||||
public TwitUser(string name)
|
||||
TwitObservable twits;
|
||||
public string Name { get; private set; }
|
||||
IDisposable channel;
|
||||
public TwitUser(string name, TwitObservable twits)
|
||||
{
|
||||
this.name = name;
|
||||
this.Name = name;
|
||||
channel = twits.Subscribe(this);
|
||||
this.twits = twits;
|
||||
}
|
||||
|
||||
public void Twit(string twit)
|
||||
{
|
||||
twits.AddTwit(new Twit { Emiter = this, Message = twit });
|
||||
}
|
||||
public void OnCompleted()
|
||||
{
|
||||
Console.WriteLine("{0} finished watching twitter", name);
|
||||
Console.WriteLine("{0} finished watching twitter", Name);
|
||||
}
|
||||
|
||||
public void OnError(Exception error)
|
||||
@@ -25,9 +34,14 @@ namespace ObserverPattern.Twits
|
||||
Console.WriteLine("Error while watching twitter: {0}", error);
|
||||
}
|
||||
|
||||
public void OnNext(string value)
|
||||
public void OnNext(Twit value)
|
||||
{
|
||||
Console.WriteLine("{0} just observed that something {1} was tweeted", name, value);
|
||||
Console.WriteLine("{0} just observed that {1} tweeted {2}", Name, value.Emiter.Name, value.Message);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
channel.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user