public void TestMethodCompositeExample() { var root = new ConcreteCompany("高雄總公司"); root.Add(new HRDept("高雄人資")); root.Add(new FinanceDept("高雄財務部")); var comp = new ConcreteCompany("台北分公司"); comp.Add(new HRDept("台北人資")); comp.Add(new FinanceDept("台北財務部")); root.Add(comp); var comp1 = new ConcreteCompany("信義辦事處"); comp1.Add(new HRDept("信義人資")); comp1.Add(new FinanceDept("信義財務部")); comp.Add(comp1); var comp2 = new ConcreteCompany("三重辦事處"); comp2.Add(new HRDept("三重人資")); comp2.Add(new FinanceDept("三重財務部")); comp.Add(comp2); Console.WriteLine("結構圖"); root.Display(1); Console.WriteLine("職責"); root.LineOfDuty(); }
public void DoWork() { ConcreteCompany root = new ConcreteCompany("總公司"); root.Add(new HRDepartment("總公司人資部")); root.Add(new FinanceDepartment("總公司財務部")); root.Add(new ITDepartment("總公司資訊服務部")); ConcreteCompany tw = new ConcreteCompany("台灣總部"); tw.Add(new HRDepartment("台灣總部人資部")); tw.Add(new FinanceDepartment("台灣總部財務部")); tw.Add(new ITDepartment("台灣總部資訊服務部")); root.Add(tw); ConcreteCompany twc = new ConcreteCompany("台灣中部分部"); twc.Add(new HRDepartment("台灣中部分人資部")); twc.Add(new FinanceDepartment("台灣中部分部財務部")); twc.Add(new ITDepartment("台灣中部分部資訊服務部")); tw.Add(twc); ConcreteCompany twc2 = new ConcreteCompany("台灣中部台中分部"); twc2.Add(new HRDepartment("台灣中部台中分部人資部")); twc2.Add(new FinanceDepartment("台灣中部台中分部財務部")); twc2.Add(new ITDepartment("台灣中部台中分部資訊服務部")); twc.Add(twc2); ConcreteCompany jp = new ConcreteCompany("日本總部"); jp.Add(new HRDepartment("日本總部人資部")); jp.Add(new FinanceDepartment("日本總部財務部")); jp.Add(new ITDepartment("日本總部資訊服務部")); root.Add(jp); ConcreteCompany jp2 = new ConcreteCompany("日本大阪分部"); jp2.Add(new HRDepartment("日本大阪分部人資部")); jp2.Add(new FinanceDepartment("日本大阪分部財務部")); jp2.Add(new ITDepartment("日本大阪分部資訊服務部")); jp.Add(jp2); Console.WriteLine("\n結構圖:"); root.Display(1); Console.WriteLine("\n工作:"); root.DoWork(); }
static void Main(string[] args) { var concreteCompany = new ConcreteCompany("总公司"); concreteCompany.Add(new HrCompany("总公司Hr")); concreteCompany.Add(new FinanceCompany("总公司财务")); var bjConcreteCompany = new ConcreteCompany("分公司1"); bjConcreteCompany.Add(new HrCompany("分公司1Hr")); bjConcreteCompany.Add(new FinanceCompany("分公司1财务")); concreteCompany.Add(bjConcreteCompany); var shConcreteCompany = new ConcreteCompany("分公司2"); shConcreteCompany.Add(new HrCompany("分公司2Hr")); shConcreteCompany.Add(new FinanceCompany("分公司2财务")); concreteCompany.Add(shConcreteCompany); concreteCompany.Display(1); concreteCompany.LineOfDuty(); }
//组合 public static void testComposite() { ConcreteCompany root = new ConcreteCompany("北京总公司"); root.Add(new HRDepartment("总公司人力资源部")); root.Add(new FinanceDepartment("总公司财务部")); ConcreteCompany comp = new ConcreteCompany("上海华东分公司"); comp.Add(new HRDepartment("华东分公司人力资源部")); comp.Add(new FinanceDepartment("华东分公司财务部")); root.Add(comp); ConcreteCompany comp1 = new ConcreteCompany("南京办事处"); comp1.Add(new HRDepartment("南京办事处人力资源部")); comp1.Add(new FinanceDepartment("南京办事处财务部")); comp.Add(comp1); ConcreteCompany comp2 = new ConcreteCompany("杭州办事处"); comp2.Add(new HRDepartment("杭州办事处人力资源部")); comp2.Add(new FinanceDepartment("杭州办事处财务部")); comp.Add(comp2); Console.WriteLine("\n结构图:"); root.Display(1); Console.WriteLine("\n职责:"); root.LineOfDuty(); Console.Read(); }