Replace conditional with polymorphism for Frequent Renter points master
authorMichael Welch <michaelgwelch@gmail.com>
Fri, 24 Feb 2012 15:19:55 +0000 (09:19 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Fri, 24 Feb 2012 15:19:55 +0000 (09:19 -0600)
RefactoringChapter1/Movie.cs
RefactoringChapter1/Price.cs

index 60c89cf..8d09892 100644 (file)
@@ -55,10 +55,7 @@ namespace RefactoringChapter1
 
         public int GetFrequentRenterPoints(int daysRented)
         {
-            return (PriceCode == NewRelease &&
-                    daysRented > 1)
-                       ? 2
-                       : 1;
+            return _price.GetFrequentRenterPoints(daysRented);
         }
 
     }
index b701c2e..9826139 100644 (file)
@@ -5,6 +5,12 @@
         public abstract int PriceCode { get; }
 
         public abstract double GetCharge(int daysRented);
+
+        public virtual int GetFrequentRenterPoints(int daysRented)
+        {
+            return 1;
+        }
+
     }
 
     public class ChildrensPrice : Price
@@ -22,6 +28,7 @@
             }
             return result;
         }
+
     }
 
     public class NewReleasePrice : Price
         {
             return daysRented * 3;
         }
+
+        public override int GetFrequentRenterPoints(int daysRented)
+        {
+            return 2;
+        }
+
     }
 
     public class RegularPrice : Price