コード例 #1
0
ファイル: Program.cs プロジェクト: niuniuliu/CSharp
        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();
        }
コード例 #2
0
        private 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();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            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 leaf = new Leaf("Leaf D");

            root.Add(leaf);
            root.Remove(leaf);

            root.Display(1);

            ConcreteCompany rootCompany = new ConcreteCompany("南京总公司");

            rootCompany.Add(new HRDepartment("总公司人力资源部"));


            Console.Read();
        }
コード例 #4
0
        public static void StartExample1()
        {
            /*
             * 注:这里的CompanyComponent1 2 3表示3种具有不同职责和功能的部门(组件)
             */
            ICompany root = new ConcreteCompany()
            {
                Name = "上海总公司"
            };

            root.Add(new CompanyComponent1()
            {
                Name = "总公司人力资源部"
            });
            root.Add(new CompanyComponent2()
            {
                Name = "总公司财务部"
            });
            root.Add(new CompanyComponent3()
            {
                Name = "总公司宣传部"
            });

            ICompany company = new ConcreteCompany()
            {
                Name = "云南分公司"
            };

            company.Add(new CompanyComponent1()
            {
                Name = "云南分公司人力资源部"
            });
            company.Add(new CompanyComponent2()
            {
                Name = "云南分公司财务部"
            });
            company.Add(new CompanyComponent3()
            {
                Name = "云南分公司宣传部"
            });

            ICompany company1 = new ConcreteCompany()
            {
                Name = "祥云支公司"
            };

            company1.Add(new CompanyComponent1()
            {
                Name = "祥云支公司人力资源部"
            });
            company1.Add(new CompanyComponent2()
            {
                Name = "祥云支公司财务部"
            });
            company1.Add(new CompanyComponent3()
            {
                Name = "祥云支公司宣传部"
            });

            //加入已经没有宣传部了
            ICompany company2 = new ConcreteCompany()
            {
                Name = "祥城镇办事处"
            };

            company2.Add(new CompanyComponent1()
            {
                Name = "祥城镇办事处人力资源部"
            });
            company2.Add(new CompanyComponent2()
            {
                Name = "祥城镇办事处财务部"
            });

            //将各个节点连接起来
            root.Add(company);
            company.Add(company1);
            company1.Add(company2);

            //显示结构图
            root.DisPlay(1);
        }