ImZivo / Hangman

0 stars 0 forks source link

IPuzzleFactory Not Robust Enough #1

Open zprobinson opened 3 years ago

zprobinson commented 3 years ago

IPuzzleFactory has two members: Create() Create(int id)

This does not allow for Puzzles to be created using all available parameters of the Puzzle constructor. Either we are creating Puzzle objects by hand, or we need more robust members in the IPuzzleFactory.

I believe there should be a string/PuzzleStatus overload for IPuzzleFactory that will allow for creating solved puzzles for the purposes of PuzzleSolutionController and PuzzleGuessHandler. Otherwise we will be forced to mutate the object to add the solution string to the puzzle.

Thoughts?

ImZivo commented 3 years ago

I think the intent of the IPuzzleFactory is solely creating puzzles rather than handling solutions. However, I do think the design of the solution has evolved since the creation of this interface.

Originally, the design said we would be generating a puzzle with some type of randomizer and that the ID would somehow be a seed to generate the same puzzle.

I think the design has shifted into more of a database backing solution. With that, I think instead the factory pattern we want to follow the repository pattern. e.g.

IPuzzleRepository
{
     GetRandom();
     Get(int id);
}

This would replace the IPuzzleFactory. I would imagine this would return return the solution of the puzzle and we would have a way to clear out the solution before sending it to the client.