예제 #1
0
        public BinaryTree <Shape> CreateObjects()
        {
            IShapeFactory shapeFactory = new ShapeFactory(_serviceProvider);

            Shape rectangleRed = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.RECTANGLE, ShapeColor = Color.Red
            });

            Shape rectangleBlue = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.RECTANGLE, ShapeColor = Color.Blue
            });

            Shape circleBlue = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.CIRCLE, ShapeColor = Color.Blue
            });

            Shape circleGreen = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.CIRCLE, ShapeColor = Color.Green
            });

            Shape triangleYellow = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.TRIANGLE, ShapeColor = Color.Yellow
            });

            Shape triangleRed = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.TRIANGLE, ShapeColor = Color.Red
            });

            Shape triangleGreen = shapeFactory.GetShape(new ShapeData {
                ShapeType = ShapeType.TRIANGLE, ShapeColor = Color.Green
            });

            BinaryTree <Shape> tree     = new BinaryTree <Shape>(rectangleRed);
            Node <Shape>       treeRoot = tree.GetRoot();

            Node <Shape> rootLeftNode  = tree.AddNodeLeft(ref treeRoot, circleBlue);
            Node <Shape> rootRightNode = tree.AddNodeRight(ref treeRoot, triangleYellow);

            tree.AddNodeLeft(ref rootLeftNode, circleGreen);
            tree.AddNodeRight(ref rootLeftNode, triangleRed);

            tree.AddNodeLeft(ref rootRightNode, rectangleBlue);
            tree.AddNodeRight(ref rootRightNode, triangleGreen);

            return(tree);
        }