-3

I am building a chess - related application, and I want to use a pre-compiled program called Stockfish as my chess engine. I am wondering what is the best practice to encapsulate the usage of the program. There are many design patterns to match - Strategy, as the program is, after all, an algorithm that operate on some context (a.k.a the game position). Adapter, as what I essentially do is to provide an interface for a pre-existing program, Facade, as the engine is, in fact, an entire subsystem of the program, or even just a regular interface, that specifies all engine operations like this example, and more. Of course, every solution requires easy switch to another engine.

What is the best practice in this case?

TGnat
  • 293
  • 3
  • 11
Aviv Aviv
  • 117

2 Answers2

5

"Of course, every solution requires easy switch to another engine"

XKCD

Rather than worry about which design pattern to use, write some code and move on. Does the code in the link work for you? If so, there's no code to write either: just use that.

Patterns are supposed to give a commonly understood name to certain patterns of writing code. They aren't Lego bricks from which you construct your application. So by all means refer to the linked code as a service as people will understand what you mean then, but that really is all that's needed here.

David Arno
  • 39,599
  • 9
  • 94
  • 129
-1

If you were to seal that application inside a wooden box, so that you could ignore what it looks like and focus only on what it does, exactly what "knobs, switches, and dials" would you put on the outside of the box, and what would each one do? Then, what "slots and doors" would you put on it, and exactly what would come out of them?