Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm coding a school project that involves MVC and threading.

This is my Main class. From there I launch the actual client.

public class Main {

    public static void main(String[] args) {

        Controller myController = new Controller();

        ScreenModel screenModel = new ScreenModel();

        ChessBoardModel chessBoardModel = new ChessBoardModel();

        ChessBoard chessBoardView = new ChessBoard(myController);

        View myView = new View(myController, chessBoardView);

        chessBoardModel.addObserver(chessBoardView);

        screenModel.addObserver(myView);

        myController.addModel(screenModel);

        myController.addChessBoardModel(chessBoardModel);

        myController.addView(myView);

    }

}

Is this too messy? I essentially have one model, the ScreenModel, that handles moving back and forth between screens and another model which handles the Chess Board. Here's my controller:

public class Controller {

    ScreenModel model;
    View view;
    User user = new User();
    ClientSocketManager csm;    
    ChessBoardModel chessBoardModel;

    /**
     * Called when the user logs in.
     */

    public Controller() {

        csm  = new ClientSocketManager();

        csm.connect("localhost", 4444);

    }

    public void login() {

        //Create userdata object upon login.

        model.handleLogin();

    }

    /**
     * Called when the user creates a game (from the main menu or the join game/games in progress screens)
     */

    public void createGame() {

        model.handleCreateGame();

    }

    /**
     * Called when the user clicks on the Join Game button in the main menu.
     */

    public void joinGameButton() {

        model.handleJoinGameButton();

    }

    /**
     * Called when the user chooses a game clicks on the "join" button.
     */

    public void joinGame() {

        model.handleJoinGame();

    }

    /**
     * Called when the user clicks on the "My Games in Progress" button.
     */

    public void myGamesInProgress() {

        model.handleMyGamesInProgress();

    }

    /**
     * Called when user cancels joining a new game or joining a game in progress.
     */

    public void cancel() {

        model.handleCancel();

    }

    /**
     * Handles making a move from the chess board.
     * @param from   The non-empty from square.
     * @param to     The non-empty to square.
     */

    public void makeMove(Cell from, Cell to) {

        chessBoardModel.handleMakeMove(from,to);

    }

    /**
     * Methods related to the Chess Board game in progress
     */

    /**
     * Called when the user clicks on the "back" button inside the Chess Board screen.
     */

    public void back() {

        model.handleBack();

    }

    /**
     * Chess Board Screen methods below
     */

    public void offerDraw() {

        chessBoardModel.handleOfferDraw();

    }

    public void resign() {

        chessBoardModel.handleResign();

    }

    /**
     * Handles flipping the board from the Chess Board Screen
     */

    public void flipBoard() {

        chessBoardModel.handleFlipBoard();

    }

    /**
     * Methods for adding models and views.
     * @param m
     */

    public void addModel(ScreenModel m){

        this.model = m;
        m.setUser(user);

    }

    public void addChessBoardModel(ChessBoardModel c) {

        this.chessBoardModel = c;
        c.setUser(user);

    }

    public void addView(View v){

        this.view = v;

    }


}

Is the controller the appropriate place for the ClientSocketManager, or should it be placed inside the model? What do you think of the rest of my controller?

share|improve this question
    
Who is using the ClientSocketManager? No one in the code given. For the code given the answer would be "Just delete it". –  abuzittin gillifirca Mar 13 at 7:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.