Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In general, rules of thumbs are exactly that: rules of thumb. Not immutable laws that one should never deviate from -- I'm pretty sure you'll find cases where doing things with your dependencies in your constructor makes more sense than otherwise.</p> <p>With that in mind, let's revisit your particular design:</p> <blockquote> <p>So this FallingPiece class has the responsability of controlling the current falling piece in a tetris game. When the piece hits the bottom or some other place, raises an event signaling that and then, through the factory, generates another new piece that starts falling again from above.</p> </blockquote> <p>Seems weird to me that <code>FallingPiece</code> triggers the piece generator after its finished.</p> <p>I'd design it something like this:</p> <pre><code>class PieceGenerator { public FallingPiece NextFallingPiece() { FallingPiece piece = new FallingPiece(NextPiece()); return piece; } // ... } class GameEngine { public PieceGenerator pieceGenerator = new PieceGenerator(); public void Start() { CreateFallingPiece(); } void CreateFallingPiece() { FallingPiece piece = pieceGenerator.NextFallingPiece(); piece.OnStop += piece_OnStop; piece.StartFalling(); } void piece_OnStop(FallingPiece piece) { piece.OnStop -= piece_OnStop; if (!GameOver()) CreateFallingPiece(); } } </code></pre> <p>At least with this design, the <code>GameEngine</code> is fully responsible for telling the Generator when to create its pieces, which seems more idiomatic than the FallingPiece having that duty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload