Trying to solve a bowling game kata (This particular type of bowling game kata) in TypeScript I end up with a class that is having just one method exposed on public interface GithubGist. Thinking about this as an utility class I have made this method static public. Doing refactoring I wrapped code pieces into methods like.
- isGameOver()
- wasStrikeThrown()
- wasSpareThrown()
- startFrame()
This in my opinion improves readibility and might help not to break DRY rule but from the other hand new issues appear.
In attached gist these methods are functions in function, which is something I feel might not be right is it indeed so?
Other options I know is making them private static and invocating them with all needed parameters passed as arguments. In case of startFrame() method this will be 4 parameters - this again I think is not right.
Yet another possibility is not using static methods at all and having one method public getScore and remaining methods private that can easily access all private properties like currentFrameScore etc. But this again requires me to use this method as instance method and creating object to use it what might be treated as too much overhead to calculate some simple value.
This question is not about TypeScript syntax itself, I know it might not be perfect as this is the first time I use it. Similarily it is not about how to solve the particular kata. The question scope is only about which approach is best/better.
Aucun commentaire:
Enregistrer un commentaire