You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You asked for code reviews on the telegram chat so here are my two cents:
Any object should have an interface. For instance, in your minesweeper game, you place the mines on the Field after the Field is created. Instead, I believe Field should be an interface with a few implementations, and then when you create each Field, you wrap them with decorators. Some of them will be wrapped in the Mined decorator. For instance:
Fieldmined = newMined (
newHidden()
);
mined.uncover(); //boom, inside Mined.uncover(), you throw an exception.Fieldclear = newHidden(
newNumber(1);//or 2, or 3, or make this dynamic based on the table's size.
);
clear.uncover();//will uncover it just fine since it is not wrapped inside Mined decorator. //Hidden.uncover() may look like this, taking into account that classes should also be immutablepublicFielduncover() {
newVisible(this);
}
Field is an interface, while Hidden, Number, Mined and Visible are all implementations of it. I think with such a design, you wouldn't even need FieldState anymore.
Furthermore, uncover() may actually return Field[] since, in Minesweeper, when you uncover a Field, sometimes more neighbouring fields are uncovered together, simultaneously.
The text was updated successfully, but these errors were encountered:
You asked for code reviews on the telegram chat so here are my two cents:
Any object should have an interface. For instance, in your minesweeper game, you place the mines on the Field after the Field is created. Instead, I believe Field should be an interface with a few implementations, and then when you create each Field, you wrap them with decorators. Some of them will be wrapped in the
Mined
decorator. For instance:Field is an interface, while Hidden, Number, Mined and Visible are all implementations of it. I think with such a design, you wouldn't even need
FieldState
anymore.Furthermore,
uncover()
may actually returnField[]
since, in Minesweeper, when you uncover a Field, sometimes more neighbouring fields are uncovered together, simultaneously.The text was updated successfully, but these errors were encountered: