Git Product home page Git Product logo

codekata's Introduction

codekata's People

Contributors

kkisiele avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

codekata's Issues

Interfaces!

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 mined = new Mined (
    new Hidden()
);
mined.uncover(); //boom, inside Mined.uncover(), you throw an exception.

Field clear = new Hidden(
    new Number(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 immutable
public Field uncover() {
    new Visible(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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.