标签:
理解如下:
接口代码:
/// <summary> /// 定义客户端调用的目标对象的接口 /// </summary> public interface IPlayMusic { string PlayMusic(string musicType); }
业务类代码:
public class PlaySubject:IPlayMusic { private static readonly PlaySubject instance = new PlaySubject(); private PlaySubject() { } public static IPlayMusic PlaySuject { get { return instance; } } #region IPlayMusic 成员 public string PlayMusic(string musicType) { if (musicType == "mp3") { return "mp3"; } else { return "other"; } } #endregion }
代理类代码:
public class PlayMusicProxy:IPlayMusic { #region IPlayMusic 成员 public string PlayMusic(string musicType) { return PlaySubject.PlaySuject.PlayMusic(musicType); } #endregion }
客户段代码:
PlayMusicProxy proxy = new PlayMusicProxy(); string str; str = proxy.PlayMusic("mp3"); Response.Write(str);
问题:
看来看去好象作用不大,好处是什么?代理类封装了业务逻辑,简化了客户端代码?
标签:
原文地址:http://www.cnblogs.com/sportdog/p/4206045.html