Commit 1049889

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-04-24 20:25:47
removed money interface.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@192 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent bec3cab
trunk/product/MoMoney.Domain/Accounting/Billing/Bill.cs
@@ -9,16 +9,16 @@ namespace MoMoney.Domain.accounting.billing
     public interface IBill : IEntity
     {
         bool is_paid_for();
-        void pay(IMoney amount_to_pay);
+        void pay(Money amount_to_pay);
         ICompany company_to_pay { get; }
-        IMoney the_amount_owed { get; }
+        Money the_amount_owed { get; }
         IDate due_date { get; }
     }
 
     [Serializable]
     public class Bill : Entity<IBill>, IBill
     {
-        public Bill(ICompany company_to_pay, IMoney the_amount_owed, DateTime due_date)
+        public Bill(ICompany company_to_pay, Money the_amount_owed, DateTime due_date)
         {
             this.company_to_pay = company_to_pay;
             this.the_amount_owed = the_amount_owed;
@@ -27,7 +27,7 @@ namespace MoMoney.Domain.accounting.billing
         }
 
         public ICompany company_to_pay { get; private set; }
-        public IMoney the_amount_owed { get; private set; }
+        public Money the_amount_owed { get; private set; }
         public IDate due_date { get; private set; }
         public IList<IPayment> payments { get; private set; }
 
@@ -36,12 +36,12 @@ namespace MoMoney.Domain.accounting.billing
             return the_amount_paid().Equals(the_amount_owed);
         }
 
-        public void pay(IMoney amount_to_pay)
+        public void pay(Money amount_to_pay)
         {
             payments.Add(new Payment(amount_to_pay));
         }
 
-        private IMoney the_amount_paid()
+        private Money the_amount_paid()
         {
             return payments.return_value_from_visiting_all_items_with(new TotalPaymentsCalculator());
         }
trunk/product/MoMoney.Domain/Accounting/Billing/BillSpecs.cs
@@ -24,7 +24,7 @@ namespace MoMoney.Domain.accounting.billing
         because b = () => { result = sut.is_paid_for(); };
 
         static bool result;
-        static IMoney amount_owed;
+        static Money amount_owed;
         static ICompany enmax;
     }
 
@@ -51,7 +51,7 @@ namespace MoMoney.Domain.accounting.billing
             return new Bill(direct_energy, one_hundred_twenty_three_dollars_fourty_five_cents, DateTime.Now);
         }
 
-        static IMoney one_hundred_twenty_three_dollars_fourty_five_cents;
+        static Money one_hundred_twenty_three_dollars_fourty_five_cents;
         static bool result;
         static ICompany direct_energy;
     }
trunk/product/MoMoney.Domain/Accounting/Billing/Company.cs
@@ -9,8 +9,8 @@ namespace MoMoney.Domain.accounting.billing
     {
         string name { get; }
         void change_name_to(string company_name);
-        void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, IMoney for_amount);
-        void pay(IAccountHolder person, IMoney amount, IDate date_of_payment);
+        void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, Money for_amount);
+        void pay(IAccountHolder person, Money amount, IDate date_of_payment);
     }
 
     [Serializable]
@@ -23,12 +23,12 @@ namespace MoMoney.Domain.accounting.billing
             name = company_name;
         }
 
-        public void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, IMoney for_amount)
+        public void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, Money for_amount)
         {
             customer.receive(new Bill(this, for_amount, that_is_due_on));
         }
 
-        public void pay(IAccountHolder person, IMoney amount, IDate date_of_payment)
+        public void pay(IAccountHolder person, Money amount, IDate date_of_payment)
         {
             person.receive(new Income(date_of_payment, amount, this));
         }
trunk/product/MoMoney.Domain/Accounting/Billing/Payment.cs
@@ -5,18 +5,18 @@ namespace MoMoney.Domain.accounting.billing
 {
     public interface IPayment : IEntity
     {
-        IMoney amount_paid { get; }
+        Money amount_paid { get; }
     }
 
     [Serializable]
     internal class Payment : Entity<IPayment>, IPayment
     {
-        public Payment(IMoney amount_paid)
+        public Payment(Money amount_paid)
         {
             this.amount_paid = amount_paid;
         }
 
-        public IMoney amount_paid { get; private set; }
+        public Money amount_paid { get; private set; }
 
         public bool Equals(Payment obj)
         {
trunk/product/MoMoney.Domain/Accounting/Billing/TotalPaymentsCalculator.cs
@@ -3,7 +3,7 @@ using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.accounting.billing
 {
-    internal class TotalPaymentsCalculator : IValueReturningVisitor<IMoney, IPayment>
+    internal class TotalPaymentsCalculator : IValueReturningVisitor<Money, IPayment>
     {
         public TotalPaymentsCalculator()
         {
@@ -15,7 +15,7 @@ namespace MoMoney.Domain.accounting.billing
             value = value.add(payment.amount_paid);
         }
 
-        public IMoney value { get; private set; }
+        public Money value { get; private set; }
 
         public void reset()
         {
trunk/product/MoMoney.Domain/Accounting/Growth/income.cs
@@ -8,14 +8,14 @@ namespace MoMoney.Domain.Accounting.Growth
     public interface IIncome : IEntity
     {
         IDate date_of_issue { get; }
-        IMoney amount_tendered { get; }
+        Money amount_tendered { get; }
         ICompany company { get; }
     }
 
     [Serializable]
     internal class Income : Entity<IIncome>, IIncome
     {
-        public Income(IDate date_of_issue, IMoney amount_tendered, ICompany company)
+        public Income(IDate date_of_issue, Money amount_tendered, ICompany company)
         {
             this.company = company;
             this.amount_tendered = amount_tendered;
@@ -23,7 +23,7 @@ namespace MoMoney.Domain.Accounting.Growth
         }
 
         public ICompany company { get; private set; }
-        public IMoney amount_tendered { get; private set; }
+        public Money amount_tendered { get; private set; }
         public IDate date_of_issue { get; private set; }
 
         public bool Equals(Income obj)
trunk/product/MoMoney.Domain/Accounting/Growth/IncomeExtensions.cs
@@ -6,9 +6,9 @@ namespace MoMoney.Domain.Accounting.Growth
 {
     public static class IncomeExtensions
     {
-        public static IMoney in_the(this IEnumerable<IIncome> income_collected, IYear year)
+        public static Money in_the(this IEnumerable<IIncome> income_collected, IYear year)
         {
-            IMoney income_for_year = new Money(0);
+            Money income_for_year = new Money(0);
             foreach (var income in income_collected) {
                 if (income.date_of_issue.is_in(year)) {
                     income_for_year = income_for_year.add(income.amount_tendered);
trunk/product/MoMoney.Domain/Accounting/AccountHolder.cs
@@ -13,7 +13,7 @@ namespace MoMoney.Domain.accounting
         void receive(IBill bill);
         void receive(IIncome income);
         IEnumerable<IBill> collect_all_the_unpaid_bills();
-        IMoney calculate_income_for(IYear year);
+        Money calculate_income_for(IYear year);
     }
 
     [Serializable]
@@ -38,7 +38,7 @@ namespace MoMoney.Domain.accounting
             return all_bills.where(bill => bill.is_not_paid());
         }
 
-        public IMoney calculate_income_for(IYear year)
+        public Money calculate_income_for(IYear year)
         {
             return income_collected.in_the(year);
         }
trunk/product/MoMoney.Domain/Accounting/AccountHolderSpecs.cs
@@ -11,10 +11,6 @@ namespace MoMoney.Domain.accounting
     [Concern(typeof (AccountHolder))]
     public abstract class behaves_like_an_account_holder : concerns_for<IAccountHolder, AccountHolder>
     {
-        //public override IAccountHolder create_sut()
-        //{
-        //    return new AccountHolder();
-        //}
     }
 
     public class when_a_customer_is_checking_for_any_bills_that_have_not_been_paid : behaves_like_an_account_holder
@@ -84,7 +80,7 @@ namespace MoMoney.Domain.accounting
 
         it should_return_the_correct_amount = () => result.should_be_equal_to(2000.as_money());
 
-        static IMoney result;
+        static Money result;
         static IIncome income_for_january_2007;
         static IIncome income_for_february_2007;
         static IIncome income_for_february_2008;
trunk/product/MoMoney.Domain/Accounting/IInvoice.cs
@@ -4,7 +4,7 @@ namespace MoMoney.Domain.accounting
 {
     public interface IInvoice
     {
-        void pay(IMoney two_thousand_dollars);
-        IMoney total();
+        void pay(Money two_thousand_dollars);
+        Money total();
     }
 }
\ No newline at end of file
trunk/product/MoMoney.Domain/Core/day.cs
@@ -1,46 +0,0 @@
-using System;
-
-namespace MoMoney.Domain.Core
-{
-    public interface IDay
-    {
-    }
-
-    [Serializable]
-    internal class Day : IDay
-    {
-        readonly DateTime the_underlying_date;
-        readonly int the_day;
-
-        public Day(DateTime the_underlying_date)
-        {
-            this.the_underlying_date = the_underlying_date;
-            the_day = the_underlying_date.Day;
-        }
-
-        public bool Equals(Day obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            return obj.the_day == the_day;
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            if (obj.GetType() != typeof (Day)) return false;
-            return Equals((Day) obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return the_day;
-        }
-
-        public override string ToString()
-        {
-            return the_underlying_date.DayOfWeek.ToString();
-        }
-    }
-}
\ No newline at end of file
trunk/product/MoMoney.Domain/Core/Money.cs
@@ -3,16 +3,12 @@ using Gorilla.Commons.Utility.Extensions;
 
 namespace MoMoney.Domain.Core
 {
-    public interface IMoney : IEquatable<IMoney>
-    {
-        long dollars { get; }
-        int cents { get; }
-        IMoney add(IMoney other);
-    }
-
     [Serializable]
-    public class Money : IMoney
+    public class Money : IEquatable<Money>
     {
+        readonly long dollars;
+        readonly int cents;
+
         public Money(long dollars) : this(dollars, 0)
         {
         }
@@ -28,10 +24,7 @@ namespace MoMoney.Domain.Core
             }
         }
 
-        public long dollars { get; private set; }
-        public int cents { get; private set; }
-
-        public IMoney add(IMoney other)
+        public Money add(Money other)
         {
             var new_dollars = dollars + other.dollars;
             if (other.cents + cents > 100)
@@ -43,7 +36,7 @@ namespace MoMoney.Domain.Core
             return new Money(new_dollars, cents + other.cents);
         }
 
-        public bool Equals(IMoney other)
+        public bool Equals(Money other)
         {
             if (ReferenceEquals(null, other)) return false;
             if (ReferenceEquals(this, other)) return true;
@@ -54,11 +47,8 @@ namespace MoMoney.Domain.Core
         {
             if (ReferenceEquals(null, obj)) return false;
             if (ReferenceEquals(this, obj)) return true;
-            if (typeof (IMoney).IsAssignableFrom(obj.GetType()))
-            {
-                return Equals((IMoney) obj);
-            }
-            return false;
+            if (obj.GetType() != typeof (Money)) return false;
+            return Equals((Money) obj);
         }
 
         public override int GetHashCode()
@@ -69,6 +59,16 @@ namespace MoMoney.Domain.Core
             }
         }
 
+        public static bool operator ==(Money left, Money right)
+        {
+            return Equals(left, right);
+        }
+
+        public static bool operator !=(Money left, Money right)
+        {
+            return !Equals(left, right);
+        }
+
         public override string ToString()
         {
             return "{0}.{1:d2}".formatted_using(dollars, cents);
trunk/product/MoMoney.Domain/Core/MoneyExtensions.cs
@@ -4,7 +4,7 @@ namespace MoMoney.Domain.Core
 {
     public static class MoneyExtensions
     {
-        public static IMoney as_money(this double amount)
+        public static Money as_money(this double amount)
         {
             var quotient = amount/0.01;
             var wholePart = (int) quotient;
@@ -16,7 +16,7 @@ namespace MoMoney.Domain.Core
             return new Money(cents/100, cents%100);
         }
 
-        public static IMoney as_money(this int amount)
+        public static Money as_money(this int amount)
         {
             var quotient = amount/0.01;
             var wholePart = (int) quotient;
trunk/product/MoMoney.Domain/Core/MoneyExtensionsSpecs.cs
@@ -9,6 +9,6 @@ namespace MoMoney.Domain.Core
 
         because b = () => { result = 1.99.as_money(); };
 
-        static IMoney result;
+        static Money result;
     }
 }
\ No newline at end of file
trunk/product/MoMoney.Domain/Core/MoneySpecs.cs
@@ -4,30 +4,30 @@ using Gorilla.Commons.Testing;
 namespace MoMoney.Domain.Core
 {
     [Concern(typeof (Money))]
-    public class when_adding_two_monies_together : concerns_for<IMoney>
+    public class when_adding_two_monies_together : concerns_for<Money>
     {
         it should_return_the_correct_money = () => result.should_be_equal_to(new Money(2, 98));
 
 
         because b = () => { result = sut.add(new Money(1, 99)); };
 
-        public override IMoney create_sut()
+        public override Money create_sut()
         {
             return new Money(0, 99);
         }
 
-        static IMoney result;
+        static Money result;
     }
 
     [Concern(typeof (Money))]
-    public class when_two_monies_of_the_same_value_are_compared_to_one_another : concerns_for<IMoney>
+    public class when_two_monies_of_the_same_value_are_compared_to_one_another : concerns_for<Money>
     {
         it they_should_be_equal = () => result.should_be_equal_to(true);
 
 
         because b = () => { result = sut.Equals(new Money(1, 99)); };
 
-        public override IMoney create_sut()
+        public override Money create_sut()
         {
             return new Money(1, 99);
         }
@@ -36,12 +36,12 @@ namespace MoMoney.Domain.Core
     }
 
     [Concern(typeof (Money))]
-    public class when_creating_a_money_with_pennies_greater_than_a_dollar : concerns_for<IMoney>
+    public class when_creating_a_money_with_pennies_greater_than_a_dollar : concerns_for<Money>
     {
         it should_create_a_money_representing_the_correct_amount_of_dollars_and_pennies =
             () => sut.should_be_equal_to(new Money(3, 00));
 
-        public override IMoney create_sut()
+        public override Money create_sut()
         {
             return new Money(1, 200);
         }
trunk/product/MoMoney.Domain/MoMoney.Domain.csproj
@@ -74,7 +74,6 @@
     <Compile Include="Accounting\Growth\IncomeExtensions.cs" />
     <Compile Include="Accounting\IInvoice.cs" />
     <Compile Include="Core\DateExtensions.cs" />
-    <Compile Include="Core\day.cs" />
     <Compile Include="Core\Entity.cs" />
     <Compile Include="Core\Money.cs" />
     <Compile Include="Core\MoneyExtensions.cs" />