Skip to Content.
Sympa Menu

patterns-discussion - RE: [patterns-discussion] A question about Coin and Wallet

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

RE: [patterns-discussion] A question about Coin and Wallet


Chronological Thread 
  • From: "Yan, Hong [IT]" <hong.yan AT citigroup.com>
  • To: "'sfedi AT yahoo.com'" <sfedi AT yahoo.com>, Patterns Discussion <patterns-discussion AT cs.uiuc.edu>
  • Cc: "Yan, Hong [IT]" <hong.yan AT citigroup.com>
  • Subject: RE: [patterns-discussion] A question about Coin and Wallet
  • Date: Fri, 12 Sep 2003 10:21:18 -0400
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion/>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

Sergio:

Thank you for your thoughts.

The Wallet is basically a hashtable that makes use of equals/hashCode
methods to faciliate storing and retrieving of objects. This is an important
part of the design. Without this Wallet class, the problem disappears.

I do not know why "metal" is part of the design. A coin with a mint defect
may become collectible and more precious than its face value. This
collectible coin has two identities: money with a face value, and a
collectible piece with a market value. Therefore CollectableCoin class
should implement two different sets of equals/hashCode methods.

As you pointed out, I need a setter method for marketValue attribute,
because it has to be assigned by another object.

rgds

Jeff

PS:
A ValueObject is equivalent to another ValueObject when all their states are
equal. For instance, all pennies are equivalent to me because I do not want
to distinguish them, therefore they are ValueObjects. The Coin.equals()
method may be implemented as follows:

public boolean equals(Object o){
return o instanceof Coin && getFaceValue() == ((Coin)
o).getFaceValue();
}

A ReferenceObject is never equal to another ReferenceObject (unless they are
the same object). This is the default way defined in
java.lang.Object.equals() as follows
public boolean equals(Object obj) {
return (this == obj);
}


-----Original Message-----
From: Sergio Bruno Fedi de Oro
[mailto:sfedi_alt AT yahoo.com]
Sent: Thursday, September 11, 2003 6:44 PM
To: Yan, Hong [IT]; Patterns Discussion
Cc: Yan, Hong [IT]
Subject: Re: [patterns-discussion] A question about Coin and Wallet


> Please be a little patient -:)

Ok. I don't understand all of your pattern references,
but I do have some thoughts about the way you
modelled this problem, that may aid you.

What you are modelling seems to be:
- pieces of metal
- coins
- market values of pieces of metals (i.e. coins)

I don't know what the wallet has to do in this problem,
it seems to be a mere physical container of some coins,
or the coins you happen to have.
But I may have misunderstood your model.

Note that the "value" of a piece of metal,
is not known by it, but by the market in which it is traded.
Moreover, if you want to be really picky, the value of something
is in the context of the transaction that involves it.
That is, I can trade a CD for two pennies with you,
so I "Buy a CD at a 2 pennies cost"
and then you can sell it at 4 pennies.
In either case, the cost of the CD varied, but so it happened to the
pennies.

This same problem can be thought in this other way:

- there are pieces of metal, shaped in a special way
- common market assign a value to these pieces of metals,
in fact, when they are assigned a typical market value,
they are instead named "coins"
- some pieces of metal has special physical properties
that vary it's value in the market
(i.e. collectable coins, special edition coins, coins from another
country)

So it seems that a piece of metal could have a collection of
PhysicalProperties,
and that each Market can have a certain ValuePolicy with which it can
assign the value of a particular coin (in it).
Note that the number inscribed in an piece of metal, the composition,
the defects in it's construction, the weigth, etc. are what
make a piece of metal a "coin" or a "collectable coin" or whatever...

Just my 2 cents ;)


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com





Archive powered by MHonArc 2.6.16.

Top of Page