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?
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.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
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.