tags:

views:

22

answers:

2

Hi all,

I'm working on a poker analysis tool with the following use case:

  1. User create Strategy class with one method: input GameState, output PokerAction
  2. User runs Analysis script, which launches a PokerGame between various Strategy subclasses (i.e. various strategies)
  3. PokerGame generates random deck
  4. PokerGame sends GameState to Strategy
  5. Strategy sends PokerAction to PokerGame
  6. PokerGame updates GameState
  7. When the game is done (managed by PokerGame), send GameResult to Analysis script
  8. User reviews output of Analysis script

There's a third-party library that performs all of the PokerGame functionality. It doesn't match at all with my own modeling of the domain in some areas (e.g. card values, etc.) but performs much of the "hard-to-code" functionality that I need (i.e. the non-trivial steps 4 - 7).

General design question When faced with a library like this (eliminates a lot of hard coding, but might constrain future design choices in related projects), do you tend to mold the rest of your project to the library? Do you refactor the key library to conform to your domain model? Or is it something else?

Thanks,

Mike

+2  A: 

If I really felt my domain model better suited me going forward, I would try to create an abstraction layer to map between the 3rd party library and my own model. This would allow me to take advantage of the library now while providing me with the flexibility to replace it in the future with another 3rd party library or one I created.

Take a look a this list of design patterns, especially the Adapter Pattern.

adrift
Thanks. I chose Adapter over Facade because I'm not sure how important it is that I have a "simpler" interface.
MikeRand
+1  A: 

I would not couple my project tightly to the library, but instead try to abstract functionality and couple both using one or more objects in between. The mediator and/or facade pattern come to my mind here.

Jim Brissom