> Do you write a getCard() function in table that calls a getCard()
function in player that calls the Hand.removeCard() function.
Yup, that's the way to do it.
> That just seems a bit tightly coupled, but I can't think of any other
way to go about it.
You've got good delegation of responsibilities going on, where the
coupling is only between adjacent layers.
"Table" doesn't care how "Player" implements getCard(), and that's a
good thing.
Using CF to learn OO might not be the quickest way to go... OOP in java
is basically the same and you would only need to learn a bit of the
language (and Eclipse) to play around. You'll gain a good debugger and
the IDE will "remind you" when you're trying to access something you
shouldn't be. (Plus you won't have to hit "refresh over an over!")
Still, there's no harm in going at it via CF; you're obviously thinking
about it hard enough so you'll "get it" either way.
Mark
-----Original Message-----
From: Ian Skinner [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 15, 2006 12:36 PM
To: CF-Talk
Subject: CFC (Object) Composition Question.
In my long struggle to get my head around OOP principals, I've been
playing with a card game application. And I have a question of how one
uses composition and best practices.
To layout the scenario, I currently have the following CFCs:
Card:
Rank
Suit
Description
Deck:
array of Cards
Shuffle()
Deal()
Hand:
Array of Cards
addCard()
removeCard()
Player:
HAND
receiveCard()
showCards()
Table
DECK
Array of Players
addPlayer()
removePlayer()
deal()
My question is about calling functions on component objects composited
inside of other component objects. For example, during the play of a
game, it is time for players to play a card, removing it from their
hands. What is the best practice to tell the table to get a card from
all the players?
Do you write a getCard() function in table that calls a getCard()
function in player that calls the Hand.removeCard() function.
That just seems a bit tightly coupled, but I can't think of any other
way to go about it.
--------------
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:260567
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4