-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
  • 4
  • 2
    You seem to be selecting patterns based on what you can argue semantically, rather than understanding the purpose of the pattern. For example, a strategy pattern has a very specific use case (_selective_ logic, think "pick and mix") which you've glossed over in favor of the vague "algorithm that operates on some context" moniker. – Flater May 05 '21 at 13:06
  • 1
    Many design patterns simply smooth over weakness & missing features in various languages. As adaptations for language shortcomings, they, like most other programming language features, are primitive tools rather than approaches to application design. See https://stackoverflow.com/q/4112796/471129 for more information on such thoughts. – Erik Eidt May 05 '21 at 14:31
  • 1
    Does this answer your question? [Choosing the right Design Pattern](https://softwareengineering.stackexchange.com/questions/227868/choosing-the-right-design-pattern) – Bart van Ingen Schenau May 06 '21 at 09:45

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
  • 38,972
  • 9
  • 88
  • 121
-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?

Mike Robinson
  • 1,765
  • 4
  • 10