/*
         * Extract the condition into its own method.
         * ·           Extract the then part and the else part into their own methods.
         *  ?? Was ist der Standardfall
         */
        public void aMethod(MyDateTime date, double quantity)
        {
            double charge = 0;

            if (date.before(SUMMER_START) || date.after(SUMMER_END))
            {
                double specialRate = _winterRate * 2;
                if (date.after(SUMMER_END))
                {
                    charge = _winterRate + specialRate;
                }
                else if (date.before(SUMMER_START))
                {
                    charge = _winterRate;
                }
                if (date.isFriday() && charge > quantity * 3)
                {
                    charge = quantity * _winterRate + _winterServiceCharge;
                }
                charge += quantity * _winterRate + _winterServiceCharge;
            }
            else
            {
                charge = quantity * _summerRate;
            }
        }
Exemplo n.º 2
0
        /*
         * Decide howto split the responsibilities of the class.
         * ·  Create a new class to express the split-off responsibilities.
         * ?rarr; If the responsibilities of the old class no longer match its name,
         * rename the old class.
         * ·  Make a link from the old to the new class.
         * ?rarr; You may need a two-way link. But don't make the back link until
         * you find you need it.
         * ·  Use Move Fieldon each field you wish to move.
         * ·  Compile and test after each move.
         * ·  Use Move Methodto move methods over from old to new. Start with lower-level
         * methods (called rather than calling) and build to the higher level.
         * ·  Compile and test after each move.
         * ·  Review and reduce the interfaces of each class.
         * ?rarr; If you did have a two -way link, examine to see whether it can be
         * made one way.
         * ·  Decide whether to expose the new class. If you do expose the class, decide whether to
         * expose it as a reference object or as an immutable value object.
         */
        public void GetCustomerCharge(MyDateTime date, double quantity)
        {
            double charge = 0;

            if (_priceConditional.NotInSeason(date))
            {
                charge = _basicPriceCaculator.GetNotInSeasonPrice(date, quantity, charge);
            }
            else
            {
                charge = _basicPriceCaculator.GetSeasonPrice(quantity);
            }
        }
        /*
         * Extract the condition into its own method.
         * ·           Extract the then part and the else part into their own methods.
         *  ?? Was ist der Standardfall - Anscheind der Elsezweig
         */
        public void aMethod(MyDateTime date, double quantity)
        {
            double charge;

            if (DateNotIinSesaon(date))
            {
                charge = WinterCharge(quantity);
            }
            else
            {
                charge = SeasonCharge(quantity);
            }
        }
Exemplo n.º 4
0
        /*
         * Extract the condition into its own method.
         * ·           Extract the then part and the else part into their own methods.
         *  ?? Was ist der Standardfall
         */
        public void aMethod(MyDateTime date, double quantity)
        {
            double charge = 0;

            if (NotInSeason(date))
            {
                charge = GetNotInSeasonPrice(date, quantity, charge);
            }
            else
            {
                charge = GetSeasonPrice(quantity);
            }
        }
        /*
         * Extract the condition into its own method.
         * ·           Extract the then part and the else part into their own methods.
         */
        public void aMethod(MyDateTime date, double quantity)
        {
            double charge;

            if (date.before(SUMMER_START) || date.after(SUMMER_END))
            {
                charge = quantity * _winterRate + _winterServiceCharge;
            }
            else
            {
                charge = quantity * _summerRate;
            }
        }
Exemplo n.º 6
0
 private double GetChargeBasisPriceByNotInSeason(MyDateTime date, double quantity, double charge)
 {
     if (OffSeason(date))
     {
         charge = OffSeasonPrice();
     }
     else if (OnSeasonPrice(date))
     {
         charge = _winterRate;
     }
     if (IsBonusDay(date, quantity, charge))
     {
         charge = BonusDayCharge(quantity);
     }
     return(charge);
 }
 private bool DateNotIinSesaon(MyDateTime date)
 {
     return(date.before(SUMMER_START) || date.after(SUMMER_END));
 }
Exemplo n.º 8
0
 private bool NotInSeason(MyDateTime date)
 {
     return(date.before(SUMMER_START) || date.after(SUMMER_END));
 }
Exemplo n.º 9
0
 private bool OffSeason(MyDateTime date)
 {
     return(date.after(SUMMER_END));
 }
Exemplo n.º 10
0
 private bool OnSeasonPrice(MyDateTime date)
 {
     return(date.before(SUMMER_START));
 }
Exemplo n.º 11
0
 private static bool IsBonusDay(MyDateTime date, double quantity, double charge)
 {
     return(date.isFriday() && charge > quantity * 3);
 }
Exemplo n.º 12
0
 private double GetNotInSeasonPrice(MyDateTime date, double quantity, double charge)
 {
     charge  = GetChargeBasisPriceByNotInSeason(date, quantity, charge);
     charge += GetChargeExtraFee(quantity);
     return(charge);
 }