Closed hygerth closed 9 years ago
BoardFactory creates new instances of Nodes, thus you will lose the observers for that node.
Expanding on what you suggested. We could "wire up" the observers in the OthelloFactory between the Score and all existing Nodes in the game. We could get rid of the BoardFactory, only send in the Board and NodeSwapper to Othello. Instead we could create a NodeSwapper interface, extend to a ClassicNodeSwapper which knows about ClassicNode, it could call upon "mark" which would notify Score about changes.
Still not entierly happy with that solutions though.
Sounds good, but I agree that it is not perfect. I have searched around on the internet for an solution to this, but everything that I have found are similar solution to what we have with the BoardFactory and worse.
For instance, do NodeSwapper need to rely on the class Board? I would say no, what if your ClassicNodeSwapper has a constructor, ...(List<ClassicNode> nodes)
and a interface swap(List<Node> nodesToSwap...)
. You would not need to know about Board because board can only give you List<Node>
and we do not want to cast it. But this way, we dont even know that there exist a board, we only are interested in pairing up nodesToSwap with the list of nodes we have. We then can invoke "mark".
Updated comment again, markdown was a bit troubeling.
That was what I desired when I wrote NodeSwapper, but since we used BoardFactory and I had not figured out an alternative I had to send a board into it.
Should I give it a try and push it up for evaluation? Or do you have something else in mind?
Give it a try, since it is a better solution (at least in theory) to only send list of nodes into NodeSwapper.
You can have a look in the feature-score branch. I have not run the test code but ComputerGame/OnePlayerGame seems to be working. I also left out some documentation.
Score now is wired up to the nodes with observers.
Seems to be providing correct results. I have rewritten the test for the NodeSwapper, is it ok to push to this branch?
Sure, I was wondering how to do them test because ClassicNodeSwapper uses "mark".
I will see if I can write a test for OthelloScore also.
Okay. It was smart of you to let the NodeCapture class to include the placed disk, in order to minimise the dependency of NodeFinder.
I don't think we actually need the NodeFinder? Those methods could be private in NodeCapturer. I think it still would conform to the SRP, or?
Did a pull request, the score feature is there at least.
A way to do this is making the Nodes observable and letting the Score observe changes, i.e. use inversion of control.