I’m working on a poker analysis tool with the following use case:
- User create Strategy class with one method: input GameState, output PokerAction
- User runs Analysis script, which launches a PokerGame between various Strategy subclasses (i.e. various strategies)
- PokerGame generates random deck
- PokerGame sends GameState to Strategy
- Strategy sends PokerAction to PokerGame
- PokerGame updates GameState
- When the game is done (managed by PokerGame), send GameResult to Analysis script
- 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
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.