Ian,

You can simplify your code, IMHO by using inheritance between your  
CFC objects.    For example, here's how one might apply an MVC  
structure  and inheritance to your CFC's:

Controller:

Table
DECK
Array of Players
addPlayer()
removePlayer()
deal()

Player: (extends controller.Table)
HAND
receiveCard()
showCards()


Model:

Deck (extends controller.Table)
array of Cards
Shuffle()
Deal()

Hand: (extends controller.Player)
Array of Cards
addCard()
removeCard()

Card (extends model.Deck)
Rank
Suit
Description

View:
( Add your user interface here in which content is directed through  
the controller and delivered through the Model objects.)

Using inheritance above, your Player component, once instantiated,  
can call the methods from the Table.

Then, per your example below, the player object can call the getCard 
() method directly while still maintaining it's own set of  
variables.  Since your Hand extends the Player, you can call that  
object and inherit it's methods and so on...

You could then store your player object variables at the SESSION  
level and maintain the array of players through the APPLICATION scope.

( A side question is to whether the Player object should extend the  
Table object or should be an extension of the Deck - kind of like a  
Chicken or the Egg discussion)

HTH,

Jon

On Nov 15, 2006, at 12:35 PM, Ian Skinner wrote:

> 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.
>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:260546
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to