예제 #1
0
    private void Start()
    {
        DMShpere   shpere1   = new DMShpere();
        DMShpere   shpere2   = new DMShpere();
        DMCube     cube1     = new DMCube();
        DMCube     cube2     = new DMCube();
        DMCube     cube3     = new DMCube();
        DMCylinder cylinder1 = new DMCylinder();

        DMShapeContainer container = new DMShapeContainer();

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

        AccountOfShapeVisitor shapeVisitor = new AccountOfShapeVisitor();

        container.RunVisitor(shapeVisitor);
        Debug.Log("图形数量:" + shapeVisitor.account);

        AccountOfCubeVisitor cubeVisitor = new AccountOfCubeVisitor();

        container.RunVisitor(cubeVisitor);
        Debug.Log("Cube数量:" + cubeVisitor.account);
    }
예제 #2
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);
    }
예제 #3
0
    private void Start()
    {
        DMCube   cube   = new DMCube();
        DMShpere shpere = new DMShpere();

        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(cube);
        container.AddShape(shpere);

        DMAmountVisitor visitor = new DMAmountVisitor();

        container.RunVisitor(visitor);

        print(visitor.Amount);
    }
예제 #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);
    }
예제 #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);
    }
예제 #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;
    }
예제 #7
0
 public override void VisitCube(DMCube cube)
 {
     amount += 12;
 }
예제 #8
0
 public abstract void VisitCube(DMCube cube);
예제 #9
0
 public override void VisitCube(DMCube cube)
 {
     //count += cube.edges;  有12
     count += 12;
 }
예제 #10
0
 public abstract void VisitCylinder(DMCylinder cylinder); //获取cylinder对象的数据
 public abstract void VisitCube(DMCube cube);             //获取cube对象的数据
예제 #11
0
 public override void VisitCube(DMCube sphere)
 {
     amount += 30;
 }
예제 #12
0
 public abstract void VisitCube(DMCube sphere);
예제 #13
0
 public override void VisitCube(DMCube cube)
 {
     account++;
 }