Exemplo n.º 1
0
    private void Start()
    {
        DMSphere   sphere1   = new DMSphere();
        DMCylinder cylinder1 = new DMCylinder();
        DMCube     cube1     = new DMCube();
        DMCube     cub2      = new DMCube();

        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(sphere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);
        container.AddShape(cub2);

        //int count = container.GetShapeCount();  //需求扩展,不符合开闭原则
        //int cubeCount=container.GetCubeCount() //需求扩展,不符合开闭原则

        //符合开闭原则
        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        print("图形数量:" + amountVisitor.amount);

        CubeAmountVisitor cubeAmount = new CubeAmountVisitor();

        container.RunVisitor(cubeAmount);
        print("cube数量:" + cubeAmount.amount);

        EdgeVisitor edgeVisitor = new EdgeVisitor();

        container.RunVisitor(edgeVisitor);
        print("edge数量:" + edgeVisitor.count);
    }
    private void Awake()
    {
        ShapeContainer container = new ShapeContainer();

        Sphere   sphere1   = new Sphere();
        Cylinder cylinder1 = new Cylinder();
        Cylinder cylinder2 = new Cylinder();
        Cube     cube1     = new Cube();
        Cube     cube2     = new Cube();
        Cube     cube3     = new Cube();


        container.AddShape(sphere1);
        container.AddShape(cylinder1);
        container.AddShape(cylinder2);
        container.AddShape(cube1);
        container.AddShape(cube2);
        container.AddShape(cube3);

        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        Debug.Log(amountVisitor.amount);

        CubeAmountVisitor cubeAmountVisitor = new CubeAmountVisitor();

        container.RunVisitor(cubeAmountVisitor);
        Debug.Log(cubeAmountVisitor.amount);

        EdgeAmountVisitor edgeAmountVisitor = new EdgeAmountVisitor();

        container.RunVisitor(edgeAmountVisitor);
        Debug.Log(edgeAmountVisitor.amount);
    }
Exemplo n.º 3
0
    private void Start()
    {
        DPShpere   shpere1   = new DPShpere();
        DPCylinder cylinder1 = new DPCylinder();
        DPCube     cube1     = new DPCube();

        DPShapeContainer container = new DPShapeContainer();

        container.AddShape(shpere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);

        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        Debug.Log("图形个数共有:" + amountVisitor.amount);
    }
Exemplo n.º 4
0
    void Start()
    {
        DMShpere   shpere1   = new DMShpere();
        DMCylinder cylinder1 = new DMCylinder();
        DMCube     cube1     = new DMCube();
        DMCube     cube2     = new DMCube();

        DMShapeContainer shapeContainer = new DMShapeContainer();

        shapeContainer.AddShape(shpere1);
        shapeContainer.AddShape(cylinder1);
        shapeContainer.AddShape(cube1);
        shapeContainer.AddShape(cube2);

        AmountVisitor amountVisitor = new AmountVisitor();

        shapeContainer.RunVisitor(amountVisitor);

        Debug.Log(amountVisitor.amount);
    }
Exemplo n.º 5
0
    void Start()
    {
        DMShpere   shpere1   = new DMShpere();
        DMCylinder cylinder1 = new DMCylinder();
        DMCube     cube1     = new DMCube();
        DMCube     cube2     = new DMCube();

        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(shpere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);
        container.AddShape(cube2);

        //int count = container.GetShapeCount();
        //int cubeCount = container.GetCubeCount();
        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        int amount = amountVisitor.amount;

        Debug.Log("图形总数:" + amount);

        CubeAmountVisitor cubeAmountVisitor = new CubeAmountVisitor();

        container.RunVisitor(cubeAmountVisitor);
        int cubeAmount = cubeAmountVisitor.amount;

        Debug.Log("Cube总数:" + cubeAmount);


        EdgeVisitor edgeVisitor = new EdgeVisitor();

        container.RunVisitor(edgeVisitor);
        int edgeAmount = edgeVisitor.amount;

        Debug.Log("边总数:" + edgeAmount);
    }
Exemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        DMSphere         sphere1   = new DMSphere();
        DMCylinder       cylinder1 = new DMCylinder();
        DMCube           cube1     = new DMCube();
        DMCube           cube2     = new DMCube();
        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(sphere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);
        container.AddShape(cube2);
        // int count = container.GetShapeCount();
        // int cubeCOunt = container.GetCubeCount();
        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        int amount = amountVisitor.amount;
        CubeAmountVisitor cubeAmountVisitor = new CubeAmountVisitor();

        container.RunVisitor(cubeAmountVisitor);
        int cubeAmount = cubeAmountVisitor.amount;
    }