views:

405

answers:

5

What should I name my class that stores costs/prices/amounts of money in CAD/USD as separate longs for dollars and cents? I has "PriceInDollars", but I don't really like that, and I always forget it. Any ideas?

EDIT: Apparently I should use BigDecimal, not reinvent the wheel. I guess I'll just use that. I did learn a lot trying to make my own class though.

Please see my other question here!

+1  A: 
  • Currency
  • Money
  • Price
  • Value (I wouldn't, though)
SLaks
Thanks for the fast answer. I don't want to go with Currency, because it is an amount in a particular currency, not a currency itself. Same goes for money, Value isn't specific enough, that leaves Price, which is better than what I had, I guess, I guess I don't need to specify the InDollars... I'll go with that unless somebody else says something I like better. Thanks!
Mk12
In a previous life we went with the more verbose CurrencyUnits. Meh.
DarkSquid
+6  A: 

I would go with either Price or Cost. Whichever one you choose, you can subclass it to get more specific.

Money and Currency seem more like they would be attributes of the price, not really suitable as the name of the price itself. Just my 2 cents (couldn't resist the pun).

Bill the Lizard
Ok, thanks.
Mk12
Currency I agree with, but how could "Money" be construed as an attribute of the price?
Laurence Gonsalves
@Laurence: I was thinking of a Money class that comes in different Currencies. Being an *attribute* of the Price might not be a totally accurate description of what I'm thinking. Money does feel like too abstract a concept for the class Mk12 is describing, though.
Bill the Lizard
A: 

I would use "Cash"

http://www.answers.com/topic/cash Money in the form of bills or coins; currency. Payment for goods or services in currency or by check.

it's not specific to any currency type, lots of verbs you can add to it for conversions and such.

jinxx0r
Except cash has very specific connotations, at least to native-English speakers, denoting the specific form of currency issued by governments as bills and coins. One does not consider a check to be cash. Nor is the abstract concept of the cost of some good or service "cash"; rather "cash" is one form used to effect the transfer of some monetary amount.
Software Monkey
+1  A: 

Why is Money a bad choice? Encapsulating whole and fractional parts along with java.util.Currency into a class is a better design than BigDecimal, IMO.

I don't like anything that ends in "InDollars", because it unnecessarily prejudices your design to USD or CAD. Why do that if the idea is more general?

duffymo
Sure, bundling the currency with the amount is good, if needed. But name a single advantage of "whole and fractional parts" as longs to represent the amount, compared to a BigDecimal.
Michael Borgwardt
No worries about rounding.
duffymo
+1  A: 

MonetaryValue :-)

Scott S. McCoy