コード例 #1
0
        public double CalculateCircleSquare(Circle circle)
        {
            if (circle == null)
            {
                throw new ArgumentNullException(nameof(Circle));
            }

            var strategy = CalcStrategies.Get <Circle>();
            var square   = strategy.CalculateSquare(circle);

            return(square);
        }
コード例 #2
0
        public double CalculateTriangleSquare(Triangle triangle)
        {
            if (triangle == null)
            {
                throw new ArgumentNullException(nameof(Triangle));
            }

            var strategy = CalcStrategies.Get <Triangle>();
            var square   = strategy.CalculateSquare(triangle);

            return(square);
        }
コード例 #3
0
        public virtual double CalculateShapeSquare(Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(Shape));
            }

            var shapeType = shape.GetType();
            var strategy  = CalcStrategies.Get(shapeType) as IShapeSquareCalcStrategy;

            if (strategy == null)
            {
                throw new ShapeNotSupportedException();
            }

            var square = strategy.CalculateSquare(shape);

            return(square);
        }