-
November 27th, 2011, 11:06 AM
#1
Designing classes
I'm designing classes for a blackjack simulator. I have CBJTable which has a CDealer which deals CCards to a CPlayer. What is the best way to send messages back and forth from CDealer and CPlayer. I need for CDealer to be able to give CPlayer a CCard and for CPlayer to let CDealer know when he Hits, Stands, Splits and Doubles. The problem is that CDealer has to know about CPlayer and CPlayer has to know about CDealer but if I use #include in both classes it causes errors obviously. What is best way to do this?
Thanks in advance,
Jack
-
November 27th, 2011, 11:33 AM
#2
Re: Designing classes
The observer pattern might be a convenient way of resolving that. Then the dealer doesn't have to have more knowledge about the players than the observer interface. The players need to know about the dealer since they have to register as observers to the dealer and also to do the actions you mentioned. Here's an example of the observer pattern http://www.netobjectives.com/resourc...ples/chapter18
I get a feeling that you will probably have to add an additional class that represent the current play. I.e. the card don't go to the player, it goes to a specific play since the player shouldn't manage the given cards at all.
-
November 28th, 2011, 07:18 AM
#3
Re: Designing classes
So I have read about Observer pattern some but how exactly would I implement it and is this the best way to handle the blackjack classes? And yes I agree with adding the other class. I was wondering if I should have like a CBettingSpot or something like that which I believe is similar to what you are saying.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|