Skip to main content
small correction
Source Link
Joop Eggen
  • 4.7k
  • 15
  • 19
  • Unabbreviated names would be nicer.
  • Immutable properties (row, column) should be made final.
  • Package private directly accessible - especially mutable - fields are not likedone should avoid.
  • ... have their uses, but not here.
  • {} in generally also are Always used.

So:

public class Cell {

    public static final int BOMB = -1;

    final int row;
    final int col;

    boolean revealed;
    int value;

    public Cell(int row, int col) {
        this.row = row;
        this.col = col;
    }

Critics:

  • cellRep belongs more to class Cell. You could make it a char method, in order to have just one char, for the board representation.
  • printBoard belongs more to Board.
  • You might consider the board size as constructor Parameters too.

Design criticism:

row and col are redundant.

There are also a couple of pitfalls you avoided, so in general the code is not bad.

  • Unabbreviated names would be nicer.
  • Immutable properties (row, column) should be made final.
  • Package private directly accessible - especially mutable - fields are not liked.
  • ... have their uses, but not here.
  • {} in generally also are Always used.

So:

public class Cell {

    public static final int BOMB = -1;

    final int row;
    final col;

    boolean revealed;
    int value;

    public Cell(int row, int col) {
        this.row = row;
        this.col = col;
    }

Critics:

  • cellRep belongs more to class Cell. You could make it a char method, in order to have just one char, for the board representation.
  • printBoard belongs more to Board.
  • You might consider the board size as constructor Parameters too.

Design criticism:

row and col are redundant.

There are also a couple of pitfalls you avoided, so in general the code is not bad.

  • Unabbreviated names would be nicer.
  • Immutable properties (row, column) should be made final.
  • Package private directly accessible - especially mutable - fields one should avoid.
  • ... have their uses, but not here.
  • {} in generally also are Always used.

So:

public class Cell {

    public static final int BOMB = -1;

    final int row;
    final int col;

    boolean revealed;
    int value;

    public Cell(int row, int col) {
        this.row = row;
        this.col = col;
    }

Critics:

  • cellRep belongs more to class Cell. You could make it a char method, in order to have just one char, for the board representation.
  • printBoard belongs more to Board.
  • You might consider the board size as constructor Parameters too.

Design criticism:

row and col are redundant.

There are also a couple of pitfalls you avoided, so in general the code is not bad.

Source Link
Joop Eggen
  • 4.7k
  • 15
  • 19

  • Unabbreviated names would be nicer.
  • Immutable properties (row, column) should be made final.
  • Package private directly accessible - especially mutable - fields are not liked.
  • ... have their uses, but not here.
  • {} in generally also are Always used.

So:

public class Cell {

    public static final int BOMB = -1;

    final int row;
    final col;

    boolean revealed;
    int value;

    public Cell(int row, int col) {
        this.row = row;
        this.col = col;
    }

Critics:

  • cellRep belongs more to class Cell. You could make it a char method, in order to have just one char, for the board representation.
  • printBoard belongs more to Board.
  • You might consider the board size as constructor Parameters too.

Design criticism:

row and col are redundant.

There are also a couple of pitfalls you avoided, so in general the code is not bad.