Permalink
Browse files

last set of changes to Day 31

  • Loading branch information...
1 parent c61537f commit 89ce69ca1c202b8330ca7c80b06fe0193fef0f43 Sean Chambers committed Aug 28, 2009
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using LosTechies.DaysOfRefactoring.SampleCode.BreakMethod.After;
+
+namespace LosTechies.DaysOfRefactoring.SampleCode.ReplaceWithPolymorphism.After
+{
+ public abstract class Customer
+ {
+ public abstract decimal DiscountPercentage { get; }
+ }
+
+ public class Employee : Customer
+ {
+ public override decimal DiscountPercentage
+ {
+ get { return 0.15m; }
+ }
+ }
+
+ public class NonEmployee : Customer
+ {
+ public override decimal DiscountPercentage
+ {
+ get { return 0.05m; }
+ }
+ }
+
+ public class OrderProcessor
+ {
+ public decimal ProcessOrder(Customer customer, IEnumerable<Product> products)
+ {
+ // do some processing of order
+ decimal orderTotal = products.Sum(p => p.Price);
+
+ orderTotal -= orderTotal * customer.DiscountPercentage;
+
+ return orderTotal;
+ }
+ }
+}
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using LosTechies.DaysOfRefactoring.SampleCode.BreakMethod.After;
+
+namespace LosTechies.DaysOfRefactoring.SampleCode.ReplaceWithPolymorphism.Before
+{
+ public abstract class Customer
+ {
+ }
+
+ public class Employee : Customer
+ {
+ }
+
+ public class NonEmployee : Customer
+ {
+ }
+
+ public class OrderProcessor
+ {
+ public decimal ProcessOrder(Customer customer, IEnumerable<Product> products)
+ {
+ // do some processing of order
+ decimal orderTotal = products.Sum(p => p.Price);
+
+ Type customerType = customer.GetType();
+ if (customerType == typeof(Employee))
+ {
+ orderTotal -= orderTotal * 0.15m;
+ }
+ else if (customerType == typeof(NonEmployee))
+ {
+ orderTotal -= orderTotal * 0.05m;
+ }
+
+ return orderTotal;
+ }
+ }
+}
@@ -91,6 +91,8 @@
<Compile Include="Day2_MoveMethod\BankAccount_Before.cs" />
<Compile Include="Day30_ReturnASAP\Order_After.cs" />
<Compile Include="Day30_ReturnASAP\Order_Before.cs" />
+ <Compile Include="Day31_ReplaceWithPolymorphism\OrderProcessor_After.cs" />
+ <Compile Include="Day31_ReplaceWithPolymorphism\OrderProcessor_Before.cs" />
<Compile Include="Day3_PullUpMethod\Vehicle_After.cs" />
<Compile Include="Day3_PullUpMethod\Vehicle_Before.cs" />
<Compile Include="Day4_PushDownMethod\Animal_Before.cs" />

0 comments on commit 89ce69c

Please sign in to comment.