The Artima Developer Community
Sponsored Link •

Design Forum
Deciding whether to use primitives or Objects

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
Mike Hogan

Posts: 3
Nickname: m081072
Registered: Oct, 2002

Deciding whether to use primitives or Objects Posted: Oct 31, 2002 8:23 AM
Reply to this message Reply
Advertisement
Hi,

When designing a method interface, a design recommendation that you often hear is to require as little as you have to to get the method done.

For example, Kent Beck wrote an article called "Test First isn't about testing" (http://computer.org/software/homepage/2001/05Design/index.htm) in which he initially had a MortalityTable class that requires a Person instance in its constructor. He later improved this to take an age as an integer, to decouple his MortalityTable class from the Person class.

This establishes the precendent of an age being an integer. Now, lets say later you require ages to be floats, to deal with some crazy sounding requirement involving ages like 48.2, for example. By tying ages to an integer representation, we are exposing ourselves to potentially large change propagation if the interpretation of age changes. This problem can be compounded if you go the extreme route of one requirement at a time.

So, the bottom line is:

* When to expose primitives and when to use Objects

Topic: impossible to create a Factory Method in Java? Previous Topic   Next Topic Topic: Best design solution

Sponsored Links



Google
  Web Artima.com   

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