Design Pattern 3-Composite

xiaoxiao2021-03-06  64

Using system;

namespace Pattern {///

/// Summary description for Class1 /// public class CompositeEquipment: Equipment {System.Collections.ArrayList list = new System.Collections.ArrayList (); public CompositeEquipment (string. Name): Base (name) {// // Todo: add constructor logic hered {list.add (equipment); return base.add (equipment);} public bool remove (Equipment equipment) {list.Remove (equipment); return base.remove (equipment);} public override double discountPrice () {double res = 0; foreach (Equipment e in list) {res = e.discountPrice ();} return res PUBLIC OVERRIDE DOUBLE NETPRICE () {Double Res = 0; Foreach (Equipment E IN List) {RES = E.NETPRICE ();} return res;}

}

public abstract class Equipment {private string name; // Nett public abstract double netPrice (); // discounted prices on public abstract double discountPrice (); // member increases method public bool add (Equipment equipment) {return false;} // Deleting Parts Method Public Bool Remove (Equipment Equipment) {Return False;} // Note Here, here is provided with a component method for accessing a combined body class. Public equipment (string name) {this.name = name;} public string getname () {return this.name;}}

Public Class EQ1: Equipment {public EQ1: Base (name) {} public override double discountprice () {Return 80;} public override double netprice () {return 100;}

}

Public class EQ2: Equipment {public EQ2: Base (name) {} public override double discountprice () {return 800;} public override double netprice () {Return 1000;}

}

转载请注明原文地址:https://www.9cbs.com/read-113105.html

New Post(0)