3、等。一开始我们先不考虑Observer模式,通过一步步地重构,最终重构为Observer模式。现在有这样两个类:Microsoft和Investor,如下图所示:图3UML静态图示例它们的实现如下:专业技术资料word资料下载可编辑public class Microsoft{ private Investor _investor; private String _symbol; private double _price; public void Update() { _investor.Se
4、ndData(this); } public Investor Investor { get { return _investor; } set { _investor = value; }专业技术资料word资料下载可编辑 } public String Symbol { get { return _symbol; } set { _symbol = value; } } public double Price {
5、 get { return _price; } set { _price = value; } }}public class Investor{专业技术资料word资料下载可编辑 private string _name; public Investor(string name) { this._name = name; } public void SendData(Microsoft ms) { Console.WriteLine("Notified {
6、0} of {1}'s " + "change to {2:C}", _name, ms.Symbol,ms.Price); }}简单的客户端实现:class Program{专业技术资料word资料下载可编辑 static void Main(string[] args) { Investor investor = new Investor("Jom"); Microsoft ms = new Microsoft(); ms.Investor = investor;