Пример #1
0
        public void Rate()
        {
            //Logging - 1st refactor of S in Solid
            _logger.Log("Starting rate.");
            _logger.Log("Loading policy.");

            // load policy - open file policy.json
            //Policy source - 2nd refactor of S in Solid
            //string policyJson = PolicySource.GetPolicyFromSource();

            //Interface segragation change
            string policyJson = _policySource.GetPolicyFromSource();

            //encoding format - 3rd refactor of S in Solid
            //var policy = PolicySerializer.GetPolicyFromJsonString(policyJson);

            //Interface segragation change
            var policy = _policySerializer.GetPolicyFromString(policyJson);

            //Open/Closed Principle implementation
            //We created 3 classes each for one type insurance - auto,land,life - now it's easier to add more
            //We create an abstract class Rate which the 3 classes inherit from
            //With the factory method we return the correct instance each time
            //We create a flood policy to check the extensibility of the principle

            //var factory = new RaterFactory();
            //var rater = factory.Create(policy, this);

            //Interface segragation change
            var rater = _raterFactory.Create(policy);

            Rating = rater.Rate(policy);
            _logger.Log("Rating completed.");
        }
Пример #2
0
        public void Rate()
        {
            Loger.Log($"Start {nameof(RatingEngine.Rate)}");

            string policySource = PolicySource.GetPolicyFromSource();

            var policy = PolicySerializer.GetPolicyFromString(policySource);

            AbsRater rater = new RaterFactory().Create(policy, this);

            Rating = rater.Rate(policy);

            Loger.Log($"End {nameof(RatingEngine.Rate)}");
        }
Пример #3
0
        public void Rate()
        {
            _logger.Log("Starting rate.");

            _logger.Log("Loading policy.");

            string policyJson = _policySource.GetPolicyFromSource();

            var policy = _policySerializer.GetPolicyFromString(policyJson);

            var rater = _raterFactory.Create(policy);

            Rating = rater.Rate(policy);

            _logger.Log("Rating completed.");
        }
Пример #4
0
        public void Rate()
        {
            _logger.Log("Starting rate.");

            _logger.Log("Loading policy.");

            string policyString = _policySource.GetPolicyFromSource();

            var policy = _policySerializer.GetPolicyFromString(policyString);

            //var rater = Context.CreateRaterForPolicy(policy, Context);
            var rater = _raterFactory.Create(policy);

            Rating = rater.Rate(policy);

            _logger.Log("Rating completed.");
            #region old code before ISP
            //Logger.Log("Starting rate.");

            //Logger.Log("Loading policy.");

            //// load policy - open file policy.json
            //string policyJson = PolicySource.GetPolicyFromSource();

            //var policy = PolicySerializer.GetPolicyFromJsonString(policyJson);

            //var factory = new RaterFactory();
            //var rater = factory.Create(policy, this);
            //// first step: original behavior printed Unknown policy type when policy type was unknown
            ////rater?.Rate(policy);

            //// second step: this null check breaks LSP
            ////if (rater == null)
            ////{
            ////    Logger.Log("Unknown policy type");
            ////}
            ////else
            ////{
            ////    rater.Rate(policy);
            ////}

            //// third step: all policies are processed the same way
            //rater.Rate(policy);

            //Logger.Log("Rating completed.");
            #endregion
        }