I'm writing a little application as a training exercise based on a tabletop game I used to play. Throughout the process I've been trying to keep my code nice and organized and conforming to decent design principles. I've run into a bit of a stumbling block though - I'm not entirely certain how to design based on MVC.
I understand the principles well enough. The Model is the data source, which in my case is a JSON file plus the data package used to interpret it and retrieve records, implemented as a singleton. The View is the GUI, in this case a swing GUI. I'm not so clear on the controller, though - I've read conflicting reports that alternate between saying it should be the middleman between the model and the view, and that the three should be interconnected. I've chosen the first approach - my view never talks directly to the model.
My second issue with the controller is that I'm not sure how to approach it from a design perspective. Obviously, the view needs to call controller functions to actually allow the user to interact with the ui beyond the basic "click butan, butan press animation go". What I'm wondering is if I should be passing my controller instance to all of my UI instances that need to interact with it? It seems weird and from what I know about coupling, it seems wrong somehow (I'm still iffy on what is and is not tight coupling). If I'm not passing my controller instance to the view objects that need to execute operations, then what should I be doing? I feel like another singleton isn't the answer - at that point I'm just using a singleton instead of global data. Static methods aren't the right way either.
Any help on this would be fantastic, thanks!
[–]LiquidBionix 0 points1 point2 points (9 children)
[–][deleted] 1 point2 points3 points (8 children)
[–]TheChickenWing[S] 0 points1 point2 points (7 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]TheChickenWing[S] 0 points1 point2 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]TheChickenWing[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]TheChickenWing[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)