Ah, I see what you are getting it here. Sometimes composition is about
hiding the fact that composition was done (so then you do have to
"cover" each of the composed object's methods), and sometimes you just
want to have a Player.getHand() method.
Ask these kinds of questions to decide what you want:
1. Is it right and good that Table knows/assumes that a Player manages
his cards using Hand? Could be yes, could be no... It depends on how
much coupling you want. (Here's where java is nicer... You could define
a Hand "interface", and then assume that any future version of the
system will have something that is be able to meet the "Hand" interface
requirements.)
2. Will Player ever change so that it doesn't use Hand objects? If yes,
then don't directly expose Hand. If No, then sure, expose it... But
realize that as a side-effect you are creating an interface where
anybody having a reference to a Player object can ask for and receive
the Player's Hand! That opens the door to "cheating". Remove that
method and direct access to another Player's Hand is gone. (Again, java
interfaces are cool because you can define a very narrow interface to
Hand that is safe for anyone to use (sort of like a read-only version),
and then have a Player.getPublicHand() or Player.getTableSageHand()
method that returns the narrower type. Too bad this won't work in CF
without a lot of effort because it is not a typed language... Sigh.)
Personally, I think covering the Hand methods in Player is better... The
hope is that the number of Hand methods that Player would need to (as
public methods) is smaller than the total number of Hand methods.
Thanks
Mark
-----Original Message-----
From: Ian Skinner [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 15, 2006 4:28 PM
To: CF-Talk
Subject: RE: CFC (Object) Composition Question.
It just needs to call player.removeCard(). Basically, it is just telling
the player to remove a card. It doesn't care how the player does it. The
player would in turn call the removeCard() method of the hand.
BUT!!! How does the table call player.removeCard() method without a
method that does so? That is what I'm stumbling on. There just seems
to me that there should be something with composition that the methods
of the internal object should be available. So that one can go
something like table.player.hand.removeCard() or something along those
lines.
The only way I see doing this, which I guess is the way one is supposed
to do this, but it seems unnatural to me.
So this is the basic and incomplete idea I am currently working with.
aCard = table.getCard(1);
Table.cfc
---------
getCard
{
return players[argument.player].getCard(1);
}
Player.cfc
getCard
{
return hand.getCard(argument.card);
}
--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
---------
| 1 | |
--------- Binary Soduko
| | |
---------
"C code. C code run. Run code run. Please!"
- Cynthia Dunning
Confidentiality Notice: This message including any attachments is for
the sole use of the intended
recipient(s) and may contain confidential and privileged information.
Any unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender and
delete any copies of this message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:260597
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4