Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:18:05+00:00 2026-06-03T01:18:05+00:00

I am reading Test Driven Development: By Example . I am on chapter 13.

  • 0

I am reading Test Driven Development: By Example. I am on chapter 13. Chapter 12 and 13 introduced Plus operation to Money object. A Money object can plus by other Money object.

The author added two classes (Bank and Sum) and one interface (IExpression) to the solution. This is the class diagram of the final solution.

Class diagram

Money store amount and currency for example 10 USD, 5 BAHT, 20 CHF. The Plus method returns Sum object.

public class Money : IExpression
{
    private const string USD = "USD";
    private const string CHF = "CHF";

    public int Amount { get; protected set; }

    public string Currency { get; private set; }

    public Money(int value, string currency)
    {
        this.Amount = value;
        this.Currency = currency;
    }

    public static Money Dollar(int amount)
    {
        return new Money(amount, USD);
    }

    public static Money Franc(int amount)
    {
        return new Money(amount, CHF);
    }

    public Money Times(int times)
    {
        return new Money(this.Amount * times, this.Currency);
    }

    public IExpression Plus(Money money)
    {
        return new Sum(this, money);
    }

    public Money Reduce(string to)
    {
        return this;
    }

    public override bool Equals(object obj)
    {
        var money = obj as Money;

        if (money == null)
        {
            throw new ArgumentNullException("obj");
        }

        return this.Amount == money.Amount &&
            this.Currency == money.Currency;
    }

    public override string ToString()
    {
        return string.Format("Amount: {0} {1}", this.Amount, this.Currency);
    }
}

Sum store two Money objects which come from constructor arguments. It has one method Reduce that return new Money object (create new object by add amount of two object)

public class Sum : IExpression
{
    public Money Augend { get; set; }

    public Money Addend { get; set; }

    public Sum(Money augend, Money addend)
    {
        this.Augend = augend;
        this.Addend = addend;
    }

    public Money Reduce(string to)
    {
        var amount = this.Augend.Amount + this.Addend.Amount;

        return new Money(amount, to);
    }
}

Bank has one method – Reduce. It just call Reduce method of incoming IExpression argument.

public class Bank
{
    public Money Reduce(IExpression source, string to)
    {
        return source.Reduce(to);
    }
}

IExpression is an interface that implemented by Money and Sum.

public interface IExpression
{
    Money Reduce(string to);
}

These are my questions.

  1. Bank does nothing good for the solution at this stage. Why do I need it?
  2. Why do I need Sum since I can create and return Money object inside Plus of the class Money (Like what the author did with Times)?
  3. What is the purpose of Bank and Sum? (Right now, it doesn’t make any sense for me)
  4. I think Reduce sound strange for me as the method name. Do you think it is a good name? (please suggest)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:18:06+00:00Added an answer on June 3, 2026 at 1:18 am

    Keep reading. Kent Beck is a very smart guy. He either has a very good reason why he created the example that way, and it will be clear later on, or it’s a poor solution.

    “Reduce” is a very good name if map-reduce is the ultimate goal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading through Test Driven Development: By Example and one of the examples is
I am learning the concepts of Test-Driven Development through reading the Craftsman articles (click
I have been reading a lot about test-driven development and decided that I want
Reading over the responses to this question Disadvantages of Test Driven Development? I got
I'm currently reading books and articles about Test Driven Development, both in the case
After spending some hours reading about Unit Testing and test driven development here on
I've been reading a lot about Unit tests and Test Driven developemnt. Recently, I
reading the SCJP book, I've found something like this in the chapter 1 self-test
How to write a unit test framework? Can anyone suggest some good reading? I
I was reading this blog post: http://www.shakie.co.uk/ramblings/feature-driven-development-riding-the-waves-of-change/ and came across the part about TestDox:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.