Exemple #1
0
        static void Main(string[] args)
        {
            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();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // 测试类(Client):三个公司,阿里巴巴、淘宝、阿里云,
            // 其中,淘宝和阿里云是阿里巴巴的子公司,
            // 同时,每个公司又有自己的研发部门和人资部门。
            Company alibaba = new ConcreteCompany("Alibaba", "B2B");
            Company taobao  = new ConcreteCompany("Taobao", "C2C");
            Company aliyun  = new ConcreteCompany("Aliyun", "Cloud Compution");

            Company aliHrDepartment       = new Department("Alibaba HR Department");
            Company aliResearchDepartment = new Department("Alibaba RESEARCH Department");

            Company taobaoHrDepartment       = new Department("Taobao HR Department");
            Company taobaoResearchDepartment = new Department("Taobao RESEARCH Department");

            Company aliyunHrDepartment       = new Department("Aliyun HR Department");
            Company aliyunResearchDepartment = new Department("Aliyun RESEARCH Department");

            alibaba.Add(taobao);
            alibaba.Add(aliyun);
            alibaba.Add(aliHrDepartment);
            alibaba.Add(aliResearchDepartment);

            taobao.Add(taobaoHrDepartment);
            taobao.Add(taobaoResearchDepartment);

            aliyun.Add(aliyunHrDepartment);
            aliyun.Add(aliyunResearchDepartment);

            alibaba.Display(0);
            System.Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~\n");
            taobao.Display(0);
            System.Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~\n");
            aliyun.Display(0);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            ConcreteCompany companyRoot = new ConcreteCompany("北京總公司");

            companyRoot.Add(new HRDepartment("總公司人力資源部"));
            companyRoot.Add(new FinanceDepartment("總公司財務部"));

            ConcreteCompany companyA = new ConcreteCompany("上海華東分公司");

            companyA.Add(new HRDepartment("華東分公司人力資源部"));
            companyA.Add(new FinanceDepartment("華東分公司財務部"));
            companyRoot.Add(companyA);

            ConcreteCompany companyB = new ConcreteCompany("南京辦事處");

            companyB.Add(new HRDepartment("南京辦事處人力資源部"));
            companyB.Add(new FinanceDepartment("南京辦事處財務部"));
            companyA.Add(companyB);

            ConcreteCompany companyC = new ConcreteCompany("杭州辦事處");

            companyC.Add(new HRDepartment("杭州辦事處人力資源部"));
            companyC.Add(new FinanceDepartment("杭州辦事處財務部"));
            companyA.Add(companyC);

            Console.WriteLine("組織結構圖");
            companyRoot.Display(1);

            Console.WriteLine("\n職責");
            companyRoot.LineOfDuty();

            Console.WriteLine("\n");

            Composite root = new Composite("root");

            root.Add(new Leaf("Leaf A"));
            root.Add(new Leaf("Leaf B"));

            Composite comp = new Composite("Composite X");

            comp.Add(new Leaf("Leaf XA"));
            comp.Add(new Leaf("Leaf XB"));

            root.Add(comp);

            Composite comp2 = new Composite("Composite XY");

            comp2.Add(new Leaf("Leaf XYA"));
            comp2.Add(new Leaf("Leaf XYB"));

            comp.Add(comp2);

            root.Add(new Leaf("Leaf C"));

            Leaf leafD = new Leaf("Leaf D");

            root.Add(leafD);
            root.Remove(leafD);

            root.Display(1);

            Console.ReadLine();
        }