Friday, October 19, 2007

Observer Pattern (3) Observer


// "Observer"

interface IInvestor

{

void Update(Stock stock);

}

// "ConcreteObserver"

class Investor : IInvestor

{

private string name;

private Stock stock;

// Constructor

public Investor(string name)

{

this.name = name;

}

public void Update(Stock stock)

{

Console.WriteLine("Notified {0} of {1}'s " +

"change to {2:C}", name, stock.Symbol, stock.Price);

}

// Property

public Stock Stock

{

get { return stock; }

set { stock = value; }

}

}

blog comments powered by Disqus