Example #1
0
        public Triangle(
            ThreeSides threeSides,
            ITriangleTypeCalculator triangleTypeCalculator)
        {
            if (!((threeSides.FirstSide < (threeSides.SecondSide + threeSides.ThirdSide)) &&
                  (threeSides.SecondSide < (threeSides.FirstSide + threeSides.ThirdSide)) &&
                  (threeSides.ThirdSide < (threeSides.FirstSide + threeSides.SecondSide))))
            {
                //TODO: For me, it should not be a exception, as it is a quick thing to do, but it can be refactored for another approach.
                throw new InvalidFormatTriangleException("The sides informed form one triangle invalid.");
            }

            ThreeSides = threeSides;
            _triangleTypeCalculator = triangleTypeCalculator;
        }
Example #2
0
        public ITriangle Create(
            ThreeSides threeSides, ITriangleTypeCalculator triangleTypeCalculator)
        {
            _triangle = new Triangle(threeSides, triangleTypeCalculator);

            switch (_triangle.Types)
            {
            case TriangleTypes.Equilateral:
                return(new Equilateral(_triangle));

            case TriangleTypes.Scalene:
                return(new Scalene(_triangle));

            case TriangleTypes.Isosceles:
                return(new Isosceles(_triangle));

            default:
                throw new FormatTriangleNotFindException("Format triangle not yet implemented or find.");
            }
        }