Permalink
Browse files

Added days 1-8 to the sample code

  • Loading branch information...
Sean Chambers
Sean Chambers committed Jul 16, 2009
0 parents commit fc3f55b53f46a7e7587f37dd361a3f97125ef3bb
Showing with 527 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +37 −0 LosTechies.DaysOfRefactoring.SampleCode/Day1_EncapsulateCollection/Order_After.cs
  3. +37 −0 LosTechies.DaysOfRefactoring.SampleCode/Day1_EncapsulateCollection/Order_Before.cs
  4. +16 −0 LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_After.cs
  5. +81 −0 LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_Before.cs
  6. +24 −0 LosTechies.DaysOfRefactoring.SampleCode/Day3_PullUpMethod/Vehicle_After.cs
  7. +25 −0 LosTechies.DaysOfRefactoring.SampleCode/Day3_PullUpMethod/Vehicle_Before.cs
  8. +18 −0 LosTechies.DaysOfRefactoring.SampleCode/Day4_PushDownMethod/Animal_After.cs
  9. +18 −0 LosTechies.DaysOfRefactoring.SampleCode/Day4_PushDownMethod/Animal_Before.cs
  10. +20 −0 LosTechies.DaysOfRefactoring.SampleCode/Day5_PullUpField/BankAccount_After.cs
  11. +21 −0 LosTechies.DaysOfRefactoring.SampleCode/Day5_PullUpField/BankAccount_Before.cs
  12. +15 −0 LosTechies.DaysOfRefactoring.SampleCode/Day6_PushDownField/Task_After.cs
  13. +15 −0 LosTechies.DaysOfRefactoring.SampleCode/Day6_PushDownField/Task_Before.cs
  14. +14 −0 LosTechies.DaysOfRefactoring.SampleCode/Day7_Rename/Person_After.cs
  15. +13 −0 LosTechies.DaysOfRefactoring.SampleCode/Day7_Rename/Person_Before.cs
  16. +25 −0 LosTechies.DaysOfRefactoring.SampleCode/Day8_ReplaceInheritance/Child_After.cs
  17. +14 −0 LosTechies.DaysOfRefactoring.SampleCode/Day8_ReplaceInheritance/Child_Before.cs
  18. +66 −0 LosTechies.DaysOfRefactoring.SampleCode/LosTechies.DaysOfRefactoring.SampleCode.csproj
  19. +36 −0 LosTechies.DaysOfRefactoring.SampleCode/Properties/AssemblyInfo.cs
  20. +20 −0 LosTechies.DaysOfRefactoring.sln
  21. +3 −0 README.markdown
@@ -0,0 +1,9 @@
+_ReSharper.*
+bin
+obj
+build
+dist
+*.suo
+*resharper*
+*.user
+~$*
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+
+namespace LosTechies.DaysOfRefactoring.EncapsulateCollection.After
+{
+ public class Order
+ {
+ private List<OrderLine> _orderLines;
+ private double _orderTotal;
+
+ public IEnumerable<OrderLine> OrderLines
+ {
+ get { return _orderLines; }
+ }
+
+ public void AddOrderLine(OrderLine orderLine)
+ {
+ _orderTotal += orderLine.Total;
+ _orderLines.Add(orderLine);
+ }
+
+ public void RemoveOrderLine(OrderLine orderLine)
+ {
+ orderLine = _orderLines.Find(o => o == orderLine);
+
+ if (orderLine == null)
+ return;
+
+ _orderTotal -= orderLine.Total;
+ _orderLines.Remove(orderLine);
+ }
+ }
+
+ public class OrderLine
+ {
+ public double Total { get; }
+ }
+}
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+
+namespace LosTechies.DaysOfRefactoring.EncapsulateCollection.Before
+{
+ public class Order
+ {
+ private List<OrderLine> _orderLines;
+ private double _orderTotal;
+
+ public IList<OrderLine> OrderLines
+ {
+ get { return _orderLines; }
+ }
+
+ public void AddOrderLine(OrderLine orderLine)
+ {
+ _orderTotal += orderLine.Total;
+ _orderLines.Add(orderLine);
+ }
+
+ public void RemoveOrderLine(OrderLine orderLine)
+ {
+ orderLine = _orderLines.Find(o => o == orderLine);
+
+ if (orderLine == null)
+ return;
+
+ _orderTotal -= orderLine.Total;
+ _orderLines.Remove(orderLine);
+ }
+ }
+
+ public class OrderLine
+ {
+ public double Total { get; }
+ }
+}
@@ -0,0 +1,16 @@
+namespace LosTechies.DaysOfRefactoring.MoveMethod.After
+{
+ public class BankAccount
+ {
+ public BankAccount(int accountAge, int creditScore, AccountInterest accountInterest)
+ {
+ AccountAge = accountAge;
+ CreditScore = creditScore;
+ AccountInterest = accountInterest;
+ }
+
+ public int AccountAge { get; private set; }
+ public int CreditScore { get; private set; }
+ public AccountInterest AccountInterest { get; private set; }
+ }
+}
@@ -0,0 +1,81 @@
+namespace LosTechies.DaysOfRefactoring.MoveMethod.Before
+{
+ public class BankAccount
+ {
+ public BankAccount(int accountAge, int creditScore, AccountInterest accountInterest)
+ {
+ AccountAge = accountAge;
+ CreditScore = creditScore;
+ AccountInterest = accountInterest;
+ }
+
+ public int AccountAge { get; private set; }
+ public int CreditScore { get; private set; }
+ public AccountInterest AccountInterest { get; private set; }
+
+ public double CalculateInterestRate()
+ {
+ if (CreditScore > 800)
+ return 0.02;
+
+ if (AccountAge > 10)
+ return 0.03;
+
+ return 0.05;
+ }
+ }
+
+ public class AccountInterest
+ {
+ public BankAccount Account { get; private set; }
+
+ public AccountInterest(BankAccount account)
+ {
+ Account = account;
+ }
+
+ public double InterestRate
+ {
+ get { return Account.CalculateInterestRate(); }
+ }
+
+ public bool IntroductoryRate
+ {
+ get { return Account.CalculateInterestRate() < 0.05; }
+ }
+ }
+}
+
+namespace LosTechies.DaysOfRefactoring.MoveMethod.After
+{
+ public class AccountInterest
+ {
+ public BankAccount Account { get; private set; }
+
+ public AccountInterest(BankAccount account)
+ {
+ Account = account;
+ }
+
+ public double InterestRate
+ {
+ get { return CalculateInterestRate(); }
+ }
+
+ public bool IntroductoryRate
+ {
+ get { return CalculateInterestRate() < 0.05; }
+ }
+
+ public double CalculateInterestRate()
+ {
+ if (Account.CreditScore > 800)
+ return 0.02;
+
+ if (Account.AccountAge > 10)
+ return 0.03;
+
+ return 0.05;
+ }
+ }
+}
@@ -0,0 +1,24 @@
+namespace LosTechies.DaysOfRefactoring.PullUpMethod.After
+{
+ public abstract class Vehicle
+ {
+ public void Turn(Direction direction)
+ {
+ // code here
+ }
+ }
+
+ public class Car : Vehicle
+ {
+ }
+
+ public class Motorcycle : Vehicle
+ {
+ }
+
+ public enum Direction
+ {
+ Left,
+ Right
+ }
+}
@@ -0,0 +1,25 @@
+namespace LosTechies.DaysOfRefactoring.PullUpMethod.Before
+{
+ public abstract class Vehicle
+ {
+ // other methods
+ }
+
+ public class Car : Vehicle
+ {
+ public void Turn(Direction direction)
+ {
+ // code here
+ }
+ }
+
+ public class Motorcycle : Vehicle
+ {
+ }
+
+ public enum Direction
+ {
+ Left,
+ Right
+ }
+}
@@ -0,0 +1,18 @@
+namespace LosTechies.DaysOfRefactoring.PushDownMethod.After
+{
+ public abstract class Animal
+ {
+ }
+
+ public class Dog : Animal
+ {
+ public void Bark()
+ {
+ // code to bark
+ }
+ }
+
+ public class Cat : Animal
+ {
+ }
+}
@@ -0,0 +1,18 @@
+namespace LosTechies.DaysOfRefactoring.PushDownMethod.Before
+{
+ public abstract class Animal
+ {
+ public void Bark()
+ {
+ // code to bark
+ }
+ }
+
+ public class Dog : Animal
+ {
+ }
+
+ public class Cat : Animal
+ {
+ }
+}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace LosTechies.DaysOfRefactoring.PullUpField.After
+{
+ public abstract class Account
+ {
+ protected decimal _minimumBalance = 5m;
+ }
+
+ public class CheckingAccount : Account
+ {
+ }
+
+ public class SavingsAccount : Account
+ {
+ }
+}
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace LosTechies.DaysOfRefactoring.PullUpField.Before
+{
+ public abstract class Account
+ {
+ }
+
+ public class CheckingAccount : Account
+ {
+ private decimal _minimumCheckingBalance = 5m;
+ }
+
+ public class SavingsAccount : Account
+ {
+ private decimal _minimumSavingsBalance = 5m;
+ }
+}
@@ -0,0 +1,15 @@
+namespace LosTechies.DaysOfRefactoring.PushDownField.After
+{
+ public abstract class Task
+ {
+ }
+
+ public class BugTask : Task
+ {
+ private string _resolution;
+ }
+
+ public class FeatureTask : Task
+ {
+ }
+}
@@ -0,0 +1,15 @@
+namespace LosTechies.DaysOfRefactoring.PushDownField.Before
+{
+ public abstract class Task
+ {
+ protected string _resolution;
+ }
+
+ public class BugTask : Task
+ {
+ }
+
+ public class FeatureTask : Task
+ {
+ }
+}
@@ -0,0 +1,14 @@
+namespace LosTechies.DaysOfRefactoring.Rename.After
+{
+ // Changed the class name to Employee
+ public class Employee
+ {
+ public string FirstName { get; set; }
+
+ public decimal CalculateHourlyPay()
+ {
+ // code to calculate hourly payrate
+ return 0m;
+ }
+ }
+}
@@ -0,0 +1,13 @@
+namespace LosTechies.DaysOfRefactoring.Rename.Before
+{
+ public class Person
+ {
+ public string FN { get; set; }
+
+ public decimal ClcHrlyPR()
+ {
+ // code to calculate hourly payrate
+ return 0m;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit fc3f55b

Please sign in to comment.