I'm using MVC to organise an Maths Game application that has multiple classes that are the following:
MathsGame.java
: Main class. Currently holds CardLayout which screen classes are contained in and runs the application along with other controller-like actions.DiffScreen.java
: Implements components and contains methods for use on the difficulty selection screen. Is extended fromMigJPanel
and is essentially a mix of a Model/View.GameScreen.java
: Implements components and contains methods for use on the game screen. Is extended fromMigJPanel
and is essentially a mix of a Model/View.EndGameScreen.java
: Implements components and contains methods for use on the end game screen. Is extended fromMigJPanel
and is essentially a mix of a Model/View.MigJPanel.java
: ExtendsJPanel
and sets layout toMigLayout
and adds a matte border.ScreenInterface.java
: Is implemented byDiffScreen
,GameScreen
, andEndGameScreen
and containsfinal
variables and anenum
.
I've watched some tutorials and read up on MVC, but a lot of the resources I've found on it deal with very basic programs; having one model, one view, one controller, and a main class.
I have an idea of how I must go about refactoring my program to work with MVC, but I'm unsure about a couple of things.
Am I right in saying that from what classes I have above, I should split
DiffScreen
,GameScreen
, andEndGameScreen
into Model and View classes for each? Additionally, would it be better to create one Controller class or—as I've seen suggested—not bother and instead combine it with my MainMathsGame
class? An approach I was suggested to use in a previous question here whereby I could implement a Controller interface seems useful too, but I'm not exactly sure if/how that would work with my new code.Would it be helpful/needed for a project this small to split the Model, View, and Controller classes into their own sub-packages and keep
MathsGame
in the main package?
Further Clarification:
I'm essentially wondering if having these classes would be a good implementation of MVC:
MathsGame.java
: As a main class, or possibly being my controller. Could also possibly implement a controller interface as suggested in the linked answer above.- These 3 possibly being inside their own sub-packages, let's say
GamePackage.Views
DiffView.java
GameView.java
EndGameView.java
- These 3 possibly being inside their own sub-packages, let's say
GamePackage.Model
DiffModel.java
GameModel.java
EndGameModel.java
Controller.java
: Won't be needed if MathsGame is both my main class and controller class. Could be in its own sub-packageGamePackage.Controller
if needed.MigJPanel.java
ScreenInterface.java
Additional:
- I've looked up on Model-View-Presenter. It looks to be similar and better suited to whole applications. It seems these questions are valid for that too. If this would be more fitted to what I want to do, I would be okay with that too.
I'm hope I've explained myself well enough. It is for a college project but I missed a lot last year due to illness so I'm a bit confused on these aspects. If I can clarify any part better, please leave a comment. Thanks in advance for any suggestions!