The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Domain Driven Design Temperature

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Keith Ray is multi-platform software developer and Team Leader
Domain Driven Design Temperature Posted: Mar 19, 2005 9:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Keith Ray.
Original Post: Domain Driven Design Temperature
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Keith Ray
Latest Posts From MemoRanda

Advertisement

One of the classes at SDExpo West showed an example of some programmer tests (of Test Driven Development). It was something like this:

void testConvertToCelsius() throws exception
{
   TemperatureConverter converter;
   assertDoublesEqual( 100.0, converter.convertFahrenheitToCelsius(212.0), 0.001 );
}

void testConvertToFahrenheit() throws exception
{
   TemperatureConverter converter;
   assertDoublesEqual( 212.0, converter.convertCelsiusToFahrenheit(100.0), 0.001 );
}

That's kind of lame. Eric Evan's advice from Domain Driven Design is that classes that end of "-er" or "-or" should be avoided. Here's a test [in Java] that may better reflect the domain.

void testConvertFahrenheitToCelsius() throws exception
{
   Fahrenheit tempF( 212.0 );
   Celsius tempC( 100.0 );
   Celsius tempFconvertedToC = tempF.asCelsius();
   assertDoublesEqual( tempC.value(), tempFconvertedToC.value(), 0.001 );
}
void testConvertCelsiusToFahrenheit() throws exception
{
   Celsius tempC( 100.0 );
   Fahrenheit tempF( 212.0 );
   Fahrenheit tempCconvertedToF = tempC.asFahrenheit();
   assertDoublesEqual( tempF.value(), tempCconvertedToF.value(), 0.001 );
}

The trouble with that approach is that Fahrenheit and Celsius are two different types for the same kind of measurement. Maybe these tests (and the design they would force) would be better:

void testConvertToCelsius() throws exception
{
   Temperature temp( 212.0, Temperature.FAHRENHEIT );
   assertDoublesEqual( 100.0, temp.celsius(), 0.001 );
}

void testConvertToFahrenheit() throws exception
{
   Temperature temp( 100.0, Temperature.CELSIUS );
   assertDoublesEqual( 212.0, temp.fahrenheit(), 0.001 );
   
}

Perhaps if NASA and Lockheed Martin had used Domain Driven Design when writing the software for the Mars Climate Orbiter, the 125 Million Dollar probe would not have been lost because NASA used metric units for distance and speed while Lockheed Martin used traditional English units. They didn't have to write conversion code, just class names (or "typedefs" or equivalent if using C or other non-OO programming language) that indicate the units being used. Someone expecting different units would be clued-in by the class or type names.

Read: Domain Driven Design Temperature

Topic: Don't Ask, Don't Smell Previous Topic   Next Topic Topic: Enclosures - how do others specify them?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use