CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    261

    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

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

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

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    261

    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
  •  





Click Here to Expand Forum to Full Width

Featured