This is a first stab at defining a tic-tac-toe API that is compile-time safe, as outlined in Tony's blog: "Understanding Practical API Design, Static Typing and Functional Programming" (http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/).
Although the game engine API is strongly typed, it's design implicitly introduces potential run-time errors in its consumption. Still, I like where it is going.
The trick to this is the use of Nullable. Since the output of the "move" function can't simultaneously satisfy the input types of most API functions (move, whoWon, TakeBack), I deemed a conversion function necessary. Using structs to define board state and Nullable, I could guarantee that a type-safe, non-null value is passed to the each of the API methods. What I can't guarantee is that the API consumer won't misuse the Nullable instances. Presumably, the IGameEngine API implementation is buried in a DLL and the setters on Board, WinnerBoard, PlayableBoard, and UndoBoard are internal only, so a consumer of the API can't construct invalid instances of those data types.
You need to login to post a comment.