// 建構子注入 public Socket(IElectricalPlug plug) { if (plug == null) { throw new ArgumentNullException("plug 為空值"); } this._plug = plug; }
// 裝飾者模式, 用建構子注入要被裝飾的插頭 public SecureHairDryerPlug(IElectricalPlug plug, string identity) { this.plug = plug; this.identity = identity; }